Be able to control the default class to assign when cls argument is nil. Default to IN
# File lib/net/dns/rr/classes.rb, line 26 def self.default=(str) if Classes.has_key? str @@default = Classes[str] else raise ClassArgumentError, "Unknown class #{str}" end end
Creates a new object representing an RR class. Performs some checks on the argument validity too. Il cls is nil, the default value is ANY or the one set with Classes.default=
# File lib/net/dns/rr/classes.rb, line 70 def initialize(cls) case cls when String # type in the form "A" or "NS" new_from_string(cls.upcase) when Fixnum # type in numeric form new_from_num(cls) when nil # default type, control with Classes.default= @str = Classes.invert[@@default] @num = @@default else raise ClassArgumentError, "Wrong cls class: #{cls.class}" end end
Gives in output the keys from the Classes hash in a format suited for regexps
# File lib/net/dns/rr/classes.rb, line 63 def self.regexp Classes.keys.sort.join("|") end
Returns the class in string format, as "IN" or "CH", given the numeric value
# File lib/net/dns/rr/classes.rb, line 48 def self.to_str(cls) case cls when Fixnum if Classes.invert.has_key? cls return Classes.invert[cls] else raise ClassArgumentError, "Unknown class number #{cls}" end else raise ClassArgumentError, "Wrong cls class: #{cls.class}" end end
Checks whether cls is a valid RR class.
# File lib/net/dns/rr/classes.rb, line 35 def self.valid?(cls) case cls when String return Classes.has_key?(cls) when Fixnum return Classes.invert.has_key?(cls) else raise ClassArgumentError, "Wrong cls class: #{cls.class}" end end
Returns the class in number format (default for normal use)
# File lib/net/dns/rr/classes.rb, line 117 def inspect @num end
Returns the class in numeric format, usable by the pack methods for data transfers
# File lib/net/dns/rr/classes.rb, line 129 def to_i @num.to_i end
Generated with the Darkfish Rdoc Generator 2.