Class: OSPFv2::LsType
Class Method Summary collapse
Instance Method Summary collapse
- #encode ⇒ Object (also: #enc)
-
#initialize(ls_type = 1) ⇒ LsType
constructor
A new instance of LsType.
- #to_hash ⇒ Object
- #to_i ⇒ Object
- #to_s ⇒ Object
- #to_s_short ⇒ Object
- #to_sym ⇒ Object
Constructor Details
#initialize(ls_type = 1) ⇒ LsType
Returns a new instance of LsType.
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ie/ls_type.rb', line 83 def initialize(ls_type=1) case ls_type when 1,:router_lsa ; @ls_type=1 when 2,:network_lsa ; @ls_type=2 when 3,:summary_lsa ; @ls_type=3 when 4,:asbr_summary_lsa ; @ls_type=4 when 5,:as_external_lsa ; @ls_type=5 when 7,:as_external7_lsa ; @ls_type=7 when 9,:opaque_link ; @ls_type=9 when 10,:opaque_area ; @ls_type=10 when 11,:opaque_as ; @ls_type=11 else raise ArgumentError, "Invalid LsType #{ls_type}" end end |
Class Method Details
.all ⇒ Object
35 36 37 |
# File 'lib/ie/ls_type.rb', line 35 def self.all [:router, :network, :summary, :asbr_summary, :as_external] end |
.to_i(arg) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/ie/ls_type.rb', line 39 def self.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
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/ie/ls_type.rb', line 70 def self.to_junos(arg) return arg.to_i unless arg.is_a?(Fixnum) case arg when 1 ; 'Router' when 2 ; 'Network' when 3 ; 'Summary' when 4 ; 'ASBRSum' when 5 ; 'Extern' else 'TBD' end end |
.to_sym(arg) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ie/ls_type.rb', line 55 def self.to_sym(arg) return arg unless arg.is_a?(Fixnum) case arg when 1 ; :router_lsa when 2 ; :network_lsa when 3 ; :summary_lsa when 4 ; :asbr_summary_lsa when 5 ; :as_external_lsa when 7 ; :as_external7_lsa when 9 ; :opaque_link when 10 ; :opaque_area when 11 ; :opaque_as end end |
Instance Method Details
#encode ⇒ Object Also known as: enc
121 122 123 |
# File 'lib/ie/ls_type.rb', line 121 def encode [@ls_type].pack('C') end |
#to_hash ⇒ Object
126 127 128 |
# File 'lib/ie/ls_type.rb', line 126 def to_hash to_sym end |
#to_i ⇒ Object
98 99 100 |
# File 'lib/ie/ls_type.rb', line 98 def to_i @ls_type end |
#to_s ⇒ Object
101 102 103 |
# File 'lib/ie/ls_type.rb', line 101 def to_s self.class.to_s.split('::').last + ": #{to_sym}" end |
#to_s_short ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/ie/ls_type.rb', line 104 def to_s_short case to_i when 1; 'router' when 2; 'network' when 3; 'summary' when 4; 'asbrSum' when 5; 'external' when 7; 'nssa' when 9; 'opaqLnk' when 10; 'opaqArea' when 11; 'opaqAs' end end |