Class: OSPFv2::MtMetric
Instance Method Summary collapse
- #encode ⇒ Object
- #id ⇒ Object
- #id=(val) ⇒ Object
-
#initialize(arg = {}) ⇒ MtMetric
constructor
A new instance of MtMetric.
- #metric ⇒ Object
- #metric=(val) ⇒ Object
- #parse(s) ⇒ Object
- #set(arg) ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
- #to_s_junos ⇒ Object
Constructor Details
#initialize(arg = {}) ⇒ MtMetric
Returns a new instance of MtMetric.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/ie/mt_metric.rb', line 58 def initialize(arg={}) arg = arg.dup @_id,@_metric=0,0 if arg.is_a?(Hash) set arg elsif arg.is_a?(String) parse arg elsif arg.is_a?(self.class) parse arg.encode elsif arg.is_a?(Array) and arg.size==2 @_id, @_metric = arg else raise ArgumentError, "Invalid Argument: #{arg.inspect}" end end |
Instance Method Details
#encode ⇒ Object
96 97 98 99 100 101 |
# File 'lib/ie/mt_metric.rb', line 96 def encode m = [] m << [id].pack('C') m << [metric].pack('N').unpack('C4')[1..-1].pack('C3') m.join end |
#id ⇒ Object
83 84 85 |
# File 'lib/ie/mt_metric.rb', line 83 def id @_id end |
#id=(val) ⇒ Object
86 87 88 |
# File 'lib/ie/mt_metric.rb', line 86 def id=(val) @_id=val end |
#metric ⇒ Object
89 90 91 |
# File 'lib/ie/mt_metric.rb', line 89 def metric @_metric end |
#metric=(val) ⇒ Object
92 93 94 |
# File 'lib/ie/mt_metric.rb', line 92 def metric=(val) @_metric=val end |
#parse(s) ⇒ Object
103 104 105 106 |
# File 'lib/ie/mt_metric.rb', line 103 def parse(s) @_id, *metric = s.unpack('C4') @_metric = [0,*metric].pack('C4').unpack('N')[0] end |
#set(arg) ⇒ Object
74 75 76 77 |
# File 'lib/ie/mt_metric.rb', line 74 def set(arg) @_id = arg[:id] if arg[:id] @_metric = arg[:metric] if arg[:metric] end |
#to_hash ⇒ Object
79 80 81 |
# File 'lib/ie/mt_metric.rb', line 79 def to_hash {:id=>id, :metric=> metric} end |
#to_s ⇒ Object
108 109 110 |
# File 'lib/ie/mt_metric.rb', line 108 def to_s "Topology #{id}, Metric #{metric}" end |
#to_s_junos ⇒ Object
112 113 114 |
# File 'lib/ie/mt_metric.rb', line 112 def to_s_junos "Topology (ID #{id}) -> Metric: #{metric}" end |