Class: DNS::Class

Inherits:
Object
  • Object
show all
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

QClass

Constant Summary collapse

Values =
{
  1 => :IN,
  2 => :CS,
  3 => :CH,
  4 => :HS
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#valueObject (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

#packObject



73
74
75
# File 'lib/faildns/class.rb', line 73

def pack
  [@value].pack('n')
end

#to_sObject



91
92
93
# File 'lib/faildns/class.rb', line 91

def to_s
  Values[@value].to_s
end

#to_symObject



87
88
89
# File 'lib/faildns/class.rb', line 87

def to_sym
  Values[@value]
end