Class: OSPFv2::Color_Tlv

Inherits:
Object show all
Includes:
Common, SubTlv
Defined in:
lib/lsa/tlv/color.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#ivar_to_klassname, #ivars, #set, #to_hash

Methods included from SubTlv

factory

Methods included from Tlv

factory

Constructor Details

#initialize(arg = {}) ⇒ Color_Tlv

Returns a new instance of Color_Tlv.



21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/lsa/tlv/color.rb', line 21

def initialize(arg={})
  @tlv_type = 9
  @color = 0

  if arg.is_a?(Hash) then
    set(arg.dup)
  elsif arg.is_a?(String)
    __parse(arg)
  else
    raise ArgumentError, "Invalid argument", caller
  end
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



19
20
21
# File 'lib/lsa/tlv/color.rb', line 19

def color
  @color
end

#tlv_typeObject (readonly)

Returns the value of attribute tlv_type.



19
20
21
# File 'lib/lsa/tlv/color.rb', line 19

def tlv_type
  @tlv_type
end

Instance Method Details

#__parse(s) ⇒ Object



38
39
40
# File 'lib/lsa/tlv/color.rb', line 38

def __parse(s)
  @tlv_type, _, @color = s.unpack('nnN')
end

#encodeObject



34
35
36
# File 'lib/lsa/tlv/color.rb', line 34

def encode
  [@tlv_type, 4, @color].pack('nnN')
end

#to_sObject



42
43
44
# File 'lib/lsa/tlv/color.rb', line 42

def to_s
  self.class.to_s + ": " + color.to_s
end