Class: Resolv::DNS::Name

Inherits:
Object
  • Object
show all
Defined in:
lib/rubydns/extensions/resolv.rb

Instance Method Summary collapse

Instance Method Details

#inspectObject



57
58
59
# File 'lib/rubydns/extensions/resolv.rb', line 57

def inspect
	"#<#{self.class}: #{self.to_s}>"
end

#to_sObject



53
54
55
# File 'lib/rubydns/extensions/resolv.rb', line 53

def to_s
	"#{@labels.join('.')}#{@absolute ? '.' : ''}"
end

#with_origin(origin, absolute = true) ⇒ Object

Return the name, typically absolute, with the specified origin as a suffix. If the origin is nil, don't change the name, but change it to absolute (as specified).



62
63
64
65
66
67
68
# File 'lib/rubydns/extensions/resolv.rb', line 62

def with_origin(origin, absolute = true)
	return self.class.new(@labels, absolute) if origin == nil
	
	origin = Label.split(origin) if String === origin
	
	return self.class.new(@labels + origin, absolute)
end

#without_origin(origin, absolute = false) ⇒ Object

Return the name, typically relative, without the specified origin suffix. If the origin is nil, don't change the name, but change it to absolute (as specified).



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/rubydns/extensions/resolv.rb', line 72

def without_origin(origin, absolute = false)
	return self.class.new(@labels, absolute) if origin == nil
	
	origin = Label.split(origin) if String === origin
	
	if @labels.last(origin.length) == origin
		return self.class.new(@labels.first(@labels.length - origin.length), absolute)
	else
		raise OriginError.new("#{self} does not end with #{origin.join('.')}")
	end
end