Class: OSPFv2::OspfVersion

Inherits:
Object show all
Defined in:
lib/ie/ospf_version.rb

Instance Method Summary collapse

Constructor Details

#initialize(version = 2) ⇒ OspfVersion

Returns a new instance of OspfVersion.



25
26
27
28
29
30
31
32
# File 'lib/ie/ospf_version.rb', line 25

def initialize(version=2)
  case version
  when :v2, 2 ; @ospf_version = 2
  when :v3, 3 ; @ospf_version = 3
  else
    @ospf_version = 0
  end
end

Instance Method Details

#encodeObject Also known as: enc



51
52
53
# File 'lib/ie/ospf_version.rb', line 51

def encode
  [@ospf_version].pack('C')
end

#to_hashObject



33
34
35
# File 'lib/ie/ospf_version.rb', line 33

def to_hash
  to_i
end

#to_iObject



36
37
38
# File 'lib/ie/ospf_version.rb', line 36

def to_i
  @ospf_version
end

#to_sObject



39
40
41
# File 'lib/ie/ospf_version.rb', line 39

def to_s
  self.class.to_s.split('::').last + ": #{to_sym}"
end

#to_symObject



42
43
44
45
46
47
48
49
# File 'lib/ie/ospf_version.rb', line 42

def to_sym
  case @ospf_version
  when 2  ; :v2
  when 3  ; :v3
  else
    ':v?'
  end
end