Class: LibSL::LLIPAddress
- Inherits:
-
Object
- Object
- LibSL::LLIPAddress
- Defined in:
- lib/types.rb
Instance Attribute Summary collapse
-
#ip ⇒ Object
Returns the value of attribute ip.
Class Method Summary collapse
Instance Method Summary collapse
- #encode ⇒ Object
-
#initialize(ip) ⇒ LLIPAddress
constructor
A new instance of LLIPAddress.
- #to_s ⇒ Object
Constructor Details
#initialize(ip) ⇒ LLIPAddress
Returns a new instance of LLIPAddress.
465 466 467 468 |
# File 'lib/types.rb', line 465 def initialize(ip) raise ArgumentError, "ip must be a string (e.g. 1.2.3.4)" unless ip.is_a? String @ip = ip end |
Instance Attribute Details
#ip ⇒ Object
Returns the value of attribute ip.
464 465 466 |
# File 'lib/types.rb', line 464 def ip @ip end |
Class Method Details
.decode(data) ⇒ Object
455 456 457 458 |
# File 'lib/types.rb', line 455 def self.decode(data) data = data.unpack('C4a*') return self.new(sprintf("%d.%d.%d.%d", data[0], data[1], data[2], data[3])), data[4] end |
Instance Method Details
#encode ⇒ Object
460 461 462 |
# File 'lib/types.rb', line 460 def encode() @ip.scan(/[0-9]+/).map {|s| s.to_i}.pack('C4') end |
#to_s ⇒ Object
470 471 472 |
# File 'lib/types.rb', line 470 def to_s() @ip.to_s end |