123456789_123456789_123456789_123456789_123456789_

Class: Resolv::DNS::Name

Relationships & Source Files
Inherits: Object
Defined in: lib/resolv.rb

Overview

A representation of a ::Resolv::DNS name.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Class Method Details

.create(arg)

Creates a new ::Resolv::DNS name from arg. arg can be:

Name

returns arg.

String

Creates a new Name.

[ GitHub ]

  
# File 'lib/resolv.rb', line 1255

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

Instance Attribute Details

#absolute?Boolean (readonly)

True if this name is absolute.

[ GitHub ]

  
# File 'lib/resolv.rb', line 1286

def absolute?
  return @absolute
end

Instance Method Details

#subdomain_of?(other) ⇒ Boolean

Returns true if other is a subdomain.

Example:

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

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'lib/resolv.rb', line 1312

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_s

returns the domain name as a string.

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

Example:

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"
[ GitHub ]

  
# File 'lib/resolv.rb', line 1347

def to_s
  return @labels.join('.')
end