Class: OSPFv2::LsType
Class Method Summary collapse
- .all ⇒ Object
- .ls_type_sym_to_i(arg) ⇒ Object
- .to_i(arg) ⇒ Object
- .to_junos(arg) ⇒ Object
- .to_short(arg) ⇒ Object
- .to_sym(arg) ⇒ Object
Instance Method Summary collapse
- #encode ⇒ Object (also: #enc)
-
#initialize(ls_type = 1) ⇒ LsType
constructor
A new instance of LsType.
- #is_opaque? ⇒ Boolean
- #to_hash ⇒ Object
- #to_i ⇒ Object
- #to_junos ⇒ Object
- #to_s ⇒ Object
- #to_s_short ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(ls_type = 1) ⇒ LsType
Returns a new instance of LsType.
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ie/ls_type.rb', line 125 def initialize(ls_type=1) @ls_type = case ls_type when Symbol LsType.ls_type_sym_to_i(ls_type) when Fixnum ls_type else raise ArgumentError, "Invalid LsType #{ls_type}" end end |
Class Method Details
.all ⇒ Object
68 69 70 |
# File 'lib/ie/ls_type.rb', line 68 def all [:router, :network, :summary, :asbr_summary, :as_external] end |
.ls_type_sym_to_i(arg) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/ie/ls_type.rb', line 97 def ls_type_sym_to_i(arg) return arg if arg.is_a?(Fixnum) if @ls_type_sym_to_i.has_key?(arg) @ls_type_sym_to_i[arg] else raise end end |
.to_i(arg) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ie/ls_type.rb', line 72 def to_i(arg) return arg unless arg.is_a?(Symbol) case arg.to_s when /^router(_lsa|)$/ ; @ls_type=1 when /^network(_lsa|)$/ ; @ls_type=2 when /^summary(_lsa|)$/ ; @ls_type=3 when /^asbr_summary(_lsa|)$/ ; @ls_type=4 when /^as_external(_lsa|)$/ ; @ls_type=5 #FIXME: finish and unit-test # when :as_external7_lsa ; @ls_type=7 # when :opaque_link ; @ls_type=9 # when :opaque_area ; @ls_type=10 # when :opaque_as ; @ls_type=11 end end |
.to_junos(arg) ⇒ Object
106 107 108 109 110 111 112 113 |
# File 'lib/ie/ls_type.rb', line 106 def to_junos(arg) return arg unless arg.is_a?(Fixnum) if @ls_type_junos.has_key?(arg) @ls_type_junos[arg] else raise end end |
.to_short(arg) ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'lib/ie/ls_type.rb', line 115 def to_short(arg) return arg unless arg.is_a?(Fixnum) if @ls_type_short.has_key?(arg) @ls_type_short[arg] else raise end end |
.to_sym(arg) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/ie/ls_type.rb', line 88 def to_sym(arg) return arg unless arg.is_a?(Fixnum) if @ls_type_sym.has_key?(arg) @ls_type_sym[arg] else raise end end |
Instance Method Details
#encode ⇒ Object Also known as: enc
146 147 148 |
# File 'lib/ie/ls_type.rb', line 146 def encode [@ls_type].pack('C') end |
#is_opaque? ⇒ Boolean
63 64 65 |
# File 'lib/ie/ls_type.rb', line 63 def is_opaque? (9..11) === @ls_type end |
#to_hash ⇒ Object
151 152 153 |
# File 'lib/ie/ls_type.rb', line 151 def to_hash to_sym end |
#to_i ⇒ Object
135 136 137 |
# File 'lib/ie/ls_type.rb', line 135 def to_i @ls_type end |
#to_junos ⇒ Object
159 160 161 |
# File 'lib/ie/ls_type.rb', line 159 def to_junos LsType.to_junos(to_i) end |
#to_s ⇒ Object
138 139 140 |
# File 'lib/ie/ls_type.rb', line 138 def to_s self.class.to_s.split('::').last + ": #{to_sym}" end |