Class: OSPFv2::Id
Class Method Summary collapse
Instance Method Summary collapse
- #encode ⇒ Object (also: #enc)
- #id=(val) ⇒ Object
-
#initialize(arg = 0) ⇒ Id
constructor
A new instance of Id.
- #to_hash ⇒ Object
- #to_i ⇒ Object
- #to_ip ⇒ Object
- #to_s(verbose = true) ⇒ Object
Constructor Details
#initialize(arg = 0) ⇒ Id
Returns a new instance of Id.
40 41 42 |
# File 'lib/ie/id.rb', line 40 def initialize(arg=0) self.id = arg end |
Class Method Details
Instance Method Details
#encode ⇒ Object Also known as: enc
61 62 63 |
# File 'lib/ie/id.rb', line 61 def encode [@id].pack('N') end |
#id=(val) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ie/id.rb', line 44 def id=(val) if val.is_a?(Hash) @id = val[:id] if val[:id] elsif val.is_a?(IPAddr) @id = val.to_i elsif val.is_a?(Integer) raise ArgumentError, "Invalid Argument #{val}" unless (0..0xffffffff).include?(val) @id = val elsif val.is_a?(String) @id = IPAddr.new(val).to_i elsif val.is_a?(Id) @id = val.to_i else raise ArgumentError, "Invalid Argument #{val.inspect}" end end |
#to_hash ⇒ Object
74 75 76 |
# File 'lib/ie/id.rb', line 74 def to_hash to_s_short end |
#to_i ⇒ Object
66 67 68 |
# File 'lib/ie/id.rb', line 66 def to_i @id end |
#to_ip ⇒ Object
78 79 80 |
# File 'lib/ie/id.rb', line 78 def to_ip to_s(false) end |
#to_s(verbose = true) ⇒ Object
70 71 72 |
# File 'lib/ie/id.rb', line 70 def to_s(verbose=true) verbose ? to_s_verbose : to_s_short end |