Class: DNS::Header::Type

Inherits:
Object
  • Object
show all
Defined in:
lib/faildns/header/type.rb

Overview

– QR A one bit field that specifies whether this message is a

query (0), or a response (1).

++

Constant Summary collapse

Values =
{
  0 => :QUERY,
  1 => :RESPONSE
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Type

Returns a new instance of Type.



37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/faildns/header/type.rb', line 37

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 type.')
  end
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



35
36
37
# File 'lib/faildns/header/type.rb', line 35

def value
  @value
end

Instance Method Details

#==(what) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'lib/faildns/header/type.rb', line 51

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

#to_sObject



65
66
67
# File 'lib/faildns/header/type.rb', line 65

def to_s
  Values[@value].to_s
end

#to_symObject



61
62
63
# File 'lib/faildns/header/type.rb', line 61

def to_sym
  Values[@value]
end