class Hostname

Defined in:

hostname.cr
hostname/resolve.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.[](string : String) : self #

Constructs a new Hostname by interpreting the contents of a String.

Expects an hostname like "example.com" or "example.com.".

Raises: MalformedError when the input is malformed.


[View source]
def self.[]?(string : String) : self? #

Constructs a new Hostname by interpreting the contents of a String.

Expects an hostname like "example.com" or "example.com.".

Returns: nil when the input is malformed.


[View source]
def self.new(parts : Array(String)) : self #

Constructs a new Hostname by interpreting the contents of an Array of Strings.

Expects input like: ["example", "com"].

Raises: MalformedError when the input is malformed.


[View source]
def self.new(string : String) : self #

Constructs a new Hostname by interpreting the contents of a String.

Expects an hostname like "example.com" or "example.com.".

Raises: MalformedError when the input is malformed.


[View source]
def self.new?(string : String) : self? #

Constructs a new Hostname by interpreting the contents of a String.

Expects an hostname like "example.com" or "example.com.".

Returns: nil when the input is malformed.


[View source]

Class Method Detail

def self.new?(parts : Array(String)) #

Constructs a new Hostname by interpreting the contents of an Array of Strings.

Expects input like: ["example", "com"].

Returns: nil when the input is malformed.


[View source]

Instance Method Detail

def <=>(other : Hostname) : Int #

Compares this hostname with another, returning -1, 0 or +1 depending if the hostname is less, equal or greater than the other hostname.

This compares the top level alphabetically. If they match the next next level is tried.


[View source]
def [](index : Int) : String #

[View source]
def address(family = Socket::Family::INET, type = Socket::Type::STREAM, protocol = Protocol::IP, timeout = nil) : IP::Address #

Returns the first IP::Address resolved for the hostname.

Raises: nil if no address is found.


[View source]
def address?(family = Socket::Family::INET, type = Socket::Type::STREAM, protocol = Protocol::IP, timeout = nil) : IP::Address? #

Returns the first IP::Address resolved for the hostname.

Returns: nil if no address is found.


[View source]
def addresses(family = Socket::Family::INET, type = Socket::Type::STREAM, protocol = Protocol::IP, timeout = nil) : Array(IP::Address) #

Returns an Array of IP::Addresses that were resolved for the hostname.


[View source]
def child(name : String) : Hostname #

Creates a new child hostname (subdomain).

Raises: MalformedError if the hostname is malformed.


[View source]
def child?(name : String) : Hostname? #

Creates a new child hostname (subdomain).

Returns: nil if the hostname is malformed.


[View source]
def each_address(family = Socket::Family::INET, type = Socket::Type::STREAM, protocol = Socket::Protocol::IP, timeout = nil, &) #

Yields the IP::Addresses that were resolved for the hostname.


[View source]
def levels : UInt32 #

Returns the number of levels in the hostname


[View source]
def parent(depth : Int = 1) : Hostname #

Creates the parent hostname.

Raises: Enumerable::EmptyError if the hostname is a Top-Level-Domain.


[View source]
def parent?(depth : Int = 1) : Hostname? #

Creates the parent hostname.

Returns: nil if the hostname is a Top-Level-Domain.


[View source]
def parts : Array(String) #

[View source]
def resolve(family = Socket::Family::INET, type = Socket::Type::STREAM, protocol = Socket::Protocol::IP, timeout = nil, &) #

Yields the IP::Addresses, Socket::Types, and Socket:: Protocols that were resolved for the hostname.


[View source]
def size : UInt32 #

Returns the number of characters in the whole hostname.


[View source]
def subdomain?(other : Hostname, fqn : Bool = false) : Bool #

Indicates if the reciever is a subdomain of the given hostname.


[View source]
def tld?(*tlds : String) : Bool #

Indicates if the domain has one of the given top level domains.


[View source]
def tld? : Bool #

Indicates if the domain is a top level domain.


[View source]
def tld?(tlds : Enumerable(String)) : Bool #

Indicates if the domain has one of the given top level domains.


[View source]
def tld?(tld : String) : Bool #

Indicates if the domain has the given top level domain.


[View source]
def to_s(fqn : Bool, io : IO) : Nil #

Appends the string representation of this hostname to the given IO with the option of making the hostname fully qualified.


[View source]
def to_s(io : IO) : Nil #

Appends the string representation of this hostname to the given IO.


[View source]
def to_s(fqn : Bool) : String #

Returns the string representation of this hostname with the option of making the hostname fully qualified.


[View source]