Class: OSPFv2::TosMetric
- Includes:
- Common
- Defined in:
- lib/ie/tos_metric.rb
Instance Attribute Summary collapse
-
#cost ⇒ Object
readonly
Returns the value of attribute cost.
-
#tos ⇒ Object
(also: #id)
readonly
Returns the value of attribute tos.
Instance Method Summary collapse
- #encode ⇒ Object
-
#initialize(arg = {}) ⇒ TosMetric
constructor
A new instance of TosMetric.
- #parse(s) ⇒ Object
- #to_s ⇒ Object
- #to_s_junos_style ⇒ Object
Methods included from Common
#ivar_to_klassname, #ivars, #set, #to_hash
Constructor Details
#initialize(arg = {}) ⇒ TosMetric
Returns a new instance of TosMetric.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/ie/tos_metric.rb', line 61 def initialize(arg={}) arg = arg.dup @tos,@cost=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 @tos, @cost = arg else raise ArgumentError, "Invalid Argument: #{arg.inspect}" end end |
Instance Attribute Details
#cost ⇒ Object (readonly)
Returns the value of attribute cost.
59 60 61 |
# File 'lib/ie/tos_metric.rb', line 59 def cost @cost end |
#tos ⇒ Object (readonly) Also known as: id
Returns the value of attribute tos.
59 60 61 |
# File 'lib/ie/tos_metric.rb', line 59 def tos @tos end |
Instance Method Details
#encode ⇒ Object
79 80 81 82 83 84 |
# File 'lib/ie/tos_metric.rb', line 79 def encode m = [] m << [tos].pack('C') m << [cost].pack('N').unpack('C4')[1..-1].pack('C3') m.join end |
#parse(s) ⇒ Object
86 87 88 89 |
# File 'lib/ie/tos_metric.rb', line 86 def parse(s) @tos, *cost = s.unpack('C4') @cost = [0,*cost].pack('C4').unpack('N')[0] end |
#to_s ⇒ Object
91 92 93 |
# File 'lib/ie/tos_metric.rb', line 91 def to_s self.class.to_s.split('::').last + ": tos: #{tos} cost: #{cost}" end |
#to_s_junos_style ⇒ Object
95 96 97 |
# File 'lib/ie/tos_metric.rb', line 95 def to_s_junos_style "Topology (ID #{id}) -> Metric: #{cost}" end |