Class: OSPFv2::RouterLinkType

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(router_link_type = 1) ⇒ RouterLinkType

Returns a new instance of RouterLinkType.



49
50
51
52
53
54
55
56
57
58
# File 'lib/ie/router_link_type.rb', line 49

def initialize(router_link_type=1)
  case router_link_type
  when  1, :point_to_point   ; @router_link_type=1
  when  2, :transit_network  ; @router_link_type=2
  when  3, :stub_network     ; @router_link_type=3
  when  4, :virtual_link     ; @router_link_type=4
  else
    raise ArgumentError, "Invalid RouterLinkType #{router_link_type}"
  end
end

Class Method Details

.eachObject



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

def self.each
  [:point_to_point, :transit_network, :stub_network, :virtual_link].each { |x| yield(x) } if block_given?
end

.to_i(arg) ⇒ Object



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

def self.to_i(arg)
  return arg unless arg.is_a?(Symbol)
  [:point_to_point, :transit_network, :stub_network, :virtual_link].index(arg)+1
end

.to_junos(type) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/ie/router_link_type.rb', line 40

def self.to_junos(type)
  case type.to_i
  when 1 ; 'Point-to-point'
  when 2 ; 'Transit'
  when 3 ; 'Stub'
  when 4 ; 'Virtual-link'
  else   ; type.to_i 
  end
end

Instance Method Details

#encodeObject Also known as: enc



73
74
75
# File 'lib/ie/router_link_type.rb', line 73

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

#to_hashObject



78
79
80
# File 'lib/ie/router_link_type.rb', line 78

def to_hash
  to_sym
end

#to_iObject



59
60
61
# File 'lib/ie/router_link_type.rb', line 59

def to_i
  @router_link_type
end

#to_sObject



62
63
64
# File 'lib/ie/router_link_type.rb', line 62

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

#to_symObject



65
66
67
68
69
70
71
72
# File 'lib/ie/router_link_type.rb', line 65

def to_sym
  case @router_link_type
  when 1  ; :point_to_point
  when 2  ; :transit_network
  when 3  ; :stub_network
  when 4  ; :virtual_link
  end
end