Class: DNS::Header::Opcode

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

Overview

– OPCODE A four bit field that specifies kind of query in this

message.  This value is set by the originator of a query
and copied into the response.  The values are:

0               a standard query (QUERY)

1               an inverse query (IQUERY)

2               a server status request (STATUS)

3-15            reserved for future use

++

Constant Summary collapse

Values =
{
  0  => :QUERY,
  1  => :IQUERY,
  2  => :STATUS,
  3  => :RESERVED3,
  4  => :NOTIFY,
  5  => :UPDATE,
  6  => :RESERVED6,
  7  => :RESERVED7,
  8  => :RESERVED8,
  9  => :RESERVED9,
  10 => :RESERVED10,
  11 => :RESERVED11,
  12 => :RESERVED12,
  13 => :RESERVED13,
  14 => :RESERVED14,
  15 => :RESERVED15
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(value) ⇒ Opcode

Returns a new instance of Opcode.



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/faildns/header/opcode.rb', line 60

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.



58
59
60
# File 'lib/faildns/header/opcode.rb', line 58

def value
  @value
end

Instance Method Details

#==(what) ⇒ Object



74
75
76
77
78
79
80
81
82
# File 'lib/faildns/header/opcode.rb', line 74

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



88
89
90
# File 'lib/faildns/header/opcode.rb', line 88

def to_s
  Values[@value].to_s
end

#to_symObject



84
85
86
# File 'lib/faildns/header/opcode.rb', line 84

def to_sym
  Values[@value]
end