Class: Net::DNS::RR::Classes
- Inherits:
-
Object
- Object
- Net::DNS::RR::Classes
- Defined in:
- lib/net/dns/rr/classes.rb
Overview
This is an auxiliary class to hadle RR class field in a DNS packet.
Constant Summary collapse
- Classes =
An hash with the values of each RR class stored with the respective id number
{ 'IN' => 1, # RFC 1035 'CH' => 3, # RFC 1035 'HS' => 4, # RFC 1035 'NONE' => 254, # RFC 2136 'ANY' => 255, # RFC 1035 }
- @@default =
The default value when class is nil in Resource Records
Classes["IN"]
Class Method Summary collapse
-
.default=(str) ⇒ Object
Be able to control the default class to assign when cls argument is
nil
. -
.regexp ⇒ Object
Gives in output the keys from the
Classes
hash in a format suited for regexps. -
.to_str(cls) ⇒ Object
Returns the class in string format, as “IN” or “CH”, given the numeric value.
-
.valid?(cls) ⇒ Boolean
Checks whether
cls
is a valid RR class.
Instance Method Summary collapse
-
#initialize(cls) ⇒ Classes
constructor
Creates a new object representing an RR class.
-
#inspect ⇒ Object
Returns the class in number format (default for normal use).
-
#to_i ⇒ Object
Returns the class in numeric format, usable by the pack methods for data transfers.
-
#to_s ⇒ Object
Returns the class in string format, i.d.
-
#to_str ⇒ Object
Should be used only for testing purpouses.
Constructor Details
#initialize(cls) ⇒ Classes
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=
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# 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 |
Class Method Details
.default=(str) ⇒ Object
Be able to control the default class to assign when cls argument is nil
. Default to IN
26 27 28 29 30 31 32 |
# 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 |
.regexp ⇒ Object
Gives in output the keys from the Classes
hash in a format suited for regexps
63 64 65 |
# File 'lib/net/dns/rr/classes.rb', line 63 def self.regexp Classes.keys.join("|") end |
.to_str(cls) ⇒ Object
Returns the class in string format, as “IN” or “CH”, given the numeric value
48 49 50 51 52 53 54 55 56 57 58 59 |
# 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 |
.valid?(cls) ⇒ Boolean
Checks whether cls
is a valid RR class.
35 36 37 38 39 40 41 42 43 44 |
# 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 |
Instance Method Details
#inspect ⇒ Object
Returns the class in number format (default for normal use)
117 118 119 |
# File 'lib/net/dns/rr/classes.rb', line 117 def inspect @num end |
#to_i ⇒ Object
Returns the class in numeric format, usable by the pack methods for data transfers
129 130 131 |
# File 'lib/net/dns/rr/classes.rb', line 129 def to_i @num.to_i end |
#to_s ⇒ Object
Returns the class in string format, i.d. “IN” or “CH” or such a string.
123 124 125 |
# File 'lib/net/dns/rr/classes.rb', line 123 def to_s @str end |
#to_str ⇒ Object
Should be used only for testing purpouses
135 136 137 |
# File 'lib/net/dns/rr/classes.rb', line 135 def to_str @num.to_s end |