Class: DNS::Class
- Inherits:
-
Object
- Object
- DNS::Class
- Defined in:
- lib/faildns/class.rb
Overview
– CLASS fields appear in resource records. The following CLASS mnemonics and values are defined:
IN 1 the Internet
CS 2 the CSNET class (Obsolete - used only for examples in
some obsolete RFCs)
CH 3 the CHAOS class
HS 4 Hesiod [Dyer 87] ++
Direct Known Subclasses
Constant Summary collapse
- Values =
{ 1 => :IN, 2 => :CS, 3 => :CH, 4 => :HS }
Instance Attribute Summary collapse
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #==(what) ⇒ Object
-
#initialize(value) ⇒ Class
constructor
A new instance of Class.
- #pack ⇒ Object
- #to_s ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(value) ⇒ Class
Returns a new instance of Class.
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/faildns/class.rb', line 59 def initialize (value) if value.is_a? Symbol @value = Values.find {|key, val| val == value}.first rescue nil elsif value.is_a? Integer @value = value else @value = value.value rescue nil end if !self.to_sym raise ArgumentError.new('The passed value is not a suitable class.') end end |
Instance Attribute Details
#value ⇒ Object (readonly)
Returns the value of attribute value.
57 58 59 |
# File 'lib/faildns/class.rb', line 57 def value @value end |
Class Method Details
.length(string = nil) ⇒ Object
53 54 55 |
# File 'lib/faildns/class.rb', line 53 def self.length (string=nil) 2 end |
.parse(string) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/faildns/class.rb', line 44 def self.parse (string) string.force_encoding 'BINARY' result = self.new(string.unpack('n').first) string[0, self.length] = '' return result end |
Instance Method Details
#==(what) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/faildns/class.rb', line 77 def == (what) if what.is_a? Symbol self.to_sym == what elsif value.is_a? Integer @value == what else @value == what.value rescue false end end |
#pack ⇒ Object
73 74 75 |
# File 'lib/faildns/class.rb', line 73 def pack [@value].pack('n') end |
#to_s ⇒ Object
91 92 93 |
# File 'lib/faildns/class.rb', line 91 def to_s Values[@value].to_s end |
#to_sym ⇒ Object
87 88 89 |
# File 'lib/faildns/class.rb', line 87 def to_sym Values[@value] end |