Be able to control the default type to assign when type is nil. Default to A
# File lib/net/dns/rr/types.rb, line 76 def self.default=(str) if TYPES.has_key? str @@default = TYPES[str] else raise ArgumentError, "Unknown type #{str}" end end
Creates a new object representing an RR type. Performs some checks on the argument validity too. Il type is nil, the default value is ANY or the one set with Types.default=
# File lib/net/dns/rr/types.rb, line 121 def initialize(type) case type when String # type in the form "A" or "NS" new_from_string(type.upcase) when Fixnum # type in numeric form new_from_num(type) when nil # default type, control with Types.default= @str = TYPES.invert[@@default] @num = @@default else raise ArgumentError, "Wrong type class: #{type.class}" end end
Gives in output the keys from the Types hash in a format suited for regexps
# File lib/net/dns/rr/types.rb, line 113 def self.regexp # Longest ones go first, so the regex engine will match AAAA before A. TYPES.keys.sort { |a,b| b.length <=> a.length }.join("|") end
Returns the type in string format, as "A" or "NS", given the numeric value
# File lib/net/dns/rr/types.rb, line 98 def self.to_str(type) case type when Fixnum if TYPES.invert.has_key? type TYPES.invert[type] else raise ArgumentError, "Unknown type number #{type}" end else raise ArgumentError, "Wrong type class: #{type.class}" end end
Checks whether type is a valid RR type.
# File lib/net/dns/rr/types.rb, line 85 def self.valid?(type) case type when String TYPES.has_key?(type) when Fixnum TYPES.invert.has_key?(type) else raise ArgumentError, "Wrong type class: #{type.class}" end end
Returns the type in number format (default for normal use)
# File lib/net/dns/rr/types.rb, line 140 def inspect @num end
Returns the type in numeric format, usable by the pack methods for data transfers
# File lib/net/dns/rr/types.rb, line 152 def to_i @num.to_i end
Generated with the Darkfish Rdoc Generator 2.