class

Hostname

Inherits Reference < Object

Constructors

[](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.

Source
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.

Source
new(string : String) : self

ditto

Source

Class methods

[]?(string : String) : self | Nil

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.

Source
new?(string : String) : self | Nil

ditto

Source
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.

Source

Instance methods

<=>(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.

Source
[](index : Int) : String
Source
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.

Source
address?(family = Socket::Family::INET, type = Socket::Type::STREAM, protocol = Protocol::IP, timeout = nil) : IP::Address | Nil

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

Returns: nil if no address is found.

Source
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.

Source
child(name : String) : Hostname

Creates a new child hostname (subdomain).

Raises: MalformedError if the hostname is malformed.

Source
child?(name : String) : Hostname | Nil

Creates a new child hostname (subdomain).

Returns: nil if the hostname is malformed.

Source
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.

Source
levels

Returns the number of levels in the hostname

Source
parent(depth : Int = 1) : Hostname

Creates the parent hostname.

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

Source
parent?(depth : Int = 1) : Hostname | Nil

Creates the parent hostname.

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

Source
parts
Source
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.

Source
size

Returns the number of characters in the whole hostname.

Source
subdomain?(other : Hostname, fqn : Bool = false) : Bool

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

Source
tld?(tld : String) : Bool

Indicates if the domain has the given top level domain.

Source
tld?(tlds : Enumerable(String)) : Bool

ditto

Source
tld?

Indicates if the domain is a top level domain.

Source
tld?(*tlds : String) : Bool

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

Source
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.

Source
to_s(io : IO) : Nil

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

Source
to_s(fqn : Bool) : String

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

Source

Nested types