Class: LibSL::LLIPAddress

Inherits:
Object
  • Object
show all
Defined in:
lib/types.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ip) ⇒ LLIPAddress

Returns a new instance of LLIPAddress.

Raises:

  • (ArgumentError)


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

#ipObject

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

#encodeObject



460
461
462
# File 'lib/types.rb', line 460

def encode()
	@ip.scan(/[0-9]+/).map {|s| s.to_i}.pack('C4')
end

#to_sObject



470
471
472
# File 'lib/types.rb', line 470

def to_s()
	@ip.to_s
end