Class: Resolv::DNS::Name
- Inherits:
-
Object
- Object
- Resolv::DNS::Name
- Defined in:
- lib/logmerge/resolv.rb
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #[](i) ⇒ Object
- #absolute? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(labels, absolute = true) ⇒ Name
constructor
A new instance of Name.
- #inspect ⇒ Object
- #length ⇒ Object
-
#subdomain_of?(other) ⇒ Boolean
tests subdomain-of relation.
- #to_a ⇒ Object
-
#to_s ⇒ Object
returns the domain name as a string.
Constructor Details
#initialize(labels, absolute = true) ⇒ Name
Returns a new instance of Name.
980 981 982 983 |
# File 'lib/logmerge/resolv.rb', line 980 def initialize(labels, absolute=true) @labels = labels @absolute = absolute end |
Class Method Details
.create(arg) ⇒ Object
969 970 971 972 973 974 975 976 977 978 |
# File 'lib/logmerge/resolv.rb', line 969 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 Method Details
#==(other) ⇒ Object Also known as: eql?
993 994 995 996 |
# File 'lib/logmerge/resolv.rb', line 993 def ==(other) return false unless Name === other return @labels == other.to_a && @absolute == other.absolute? end |
#[](i) ⇒ Object
1029 1030 1031 |
# File 'lib/logmerge/resolv.rb', line 1029 def [](i) return @labels[i] end |
#absolute? ⇒ Boolean
989 990 991 |
# File 'lib/logmerge/resolv.rb', line 989 def absolute? return @absolute end |
#hash ⇒ Object
1017 1018 1019 |
# File 'lib/logmerge/resolv.rb', line 1017 def hash return @labels.hash ^ @absolute.hash end |
#inspect ⇒ Object
985 986 987 |
# File 'lib/logmerge/resolv.rb', line 985 def inspect "#<#{self.class}: #{self.to_s}#{@absolute ? '.' : ''}>" end |
#length ⇒ Object
1025 1026 1027 |
# File 'lib/logmerge/resolv.rb', line 1025 def length return @labels.length end |
#subdomain_of?(other) ⇒ Boolean
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
1009 1010 1011 1012 1013 1014 1015 |
# File 'lib/logmerge/resolv.rb', line 1009 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 ⇒ Object
1021 1022 1023 |
# File 'lib/logmerge/resolv.rb', line 1021 def to_a return @labels end |
#to_s ⇒ Object
1041 1042 1043 |
# File 'lib/logmerge/resolv.rb', line 1041 def to_s return @labels.join('.') end |