Class: Resolv::DNS::Name

Class | Resolv::DNS::Name
In: | resolv.rb
Parent: | Object

### Methods

== [] absolute? create eql? hash inspect length new subdomain_of? to_a to_s

### Public Class methods

create(arg)

[Source]

    # File resolv.rb, line 965
          def self.create(arg)
            case arg
            when Name
              return arg
            when String
              return Name.new(Label.split(arg), /\.\z/ =~ arg ? true : false)
            else
              raise ArgumentError.new("cannot interpret as DNS name: #{arg.inspect}")
            end
          end

new(labels, absolute=true)

[Source]

    # File resolv.rb, line 976
          def initialize(labels, absolute=true)
            @labels = labels
            @absolute = absolute
          end

### Public Instance methods

==(other)

[Source]

    # File resolv.rb, line 989
          def ==(other)
            return false unless Name === other
            return @labels == other.to_a && @absolute == other.absolute?
          end

[](i)

[Source]

    # File resolv.rb, line 1025
          def [](i)
            return @labels[i]
          end

absolute?()

[Source]

    # File resolv.rb, line 985
          def absolute?
            return @absolute
          end

eql?(other)

Alias for #==

hash()

[Source]

    # File resolv.rb, line 1013
          def hash
            return @labels.hash ^ @absolute.hash
          end

inspect()

[Source]

    # File resolv.rb, line 981
          def inspect
            "#<#{self.class}: #{self.to_s}#{@absolute ? '.' : ''}>"
          end

length()

[Source]

    # File resolv.rb, line 1021
          def length
            return @labels.length
          end

subdomain_of?(other)

tests subdomain-of relation.

      domain = Resolv::DNS::Name.create("y.z")
      p Resolv::DNS::Name.create("w.x.y.z").subdomain_of?(domain) #=> true
      p Resolv::DNS::Name.create("x.y.z").subdomain_of?(domain) #=> true
      p Resolv::DNS::Name.create("y.z").subdomain_of?(domain) #=> false
      p Resolv::DNS::Name.create("z").subdomain_of?(domain) #=> false
      p Resolv::DNS::Name.create("x.y.z.").subdomain_of?(domain) #=> false
      p Resolv::DNS::Name.create("w.z").subdomain_of?(domain) #=> false

[Source]

    # File resolv.rb, line 1005
          def subdomain_of?(other)
            raise ArgumentError, "not a domain name: #{other.inspect}" unless Name === other
            return false if @absolute != other.absolute?
            other_len = other.length
            return false if @labels.length <= other_len
            return @labels[-other_len, other_len] == other.to_a
          end

to_a()

[Source]

    # File resolv.rb, line 1017
          def to_a
            return @labels
          end

to_s()

returns the domain name as a string.

The domain name doesn’t have a trailing dot even if the name object is absolute.

      p Resolv::DNS::Name.create("x.y.z.").to_s #=> "x.y.z"
      p Resolv::DNS::Name.create("x.y.z").to_s #=> "x.y.z"

[Source]

    # File resolv.rb, line 1037
          def to_s
            return @labels.join('.')
          end

[Validate]