Class: XBeeRuby::Address64

Inherits:
Address
  • Object
show all
Defined in:
lib/xbee-ruby/address_64.rb

Constant Summary collapse

BROADCAST =
Address64.new 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff
COORDINATOR =
Address64.new 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(b1, b2, b3, b4, b5, b6, b7, b8) ⇒ Address64

Returns a new instance of Address64.



17
18
19
# File 'lib/xbee-ruby/address_64.rb', line 17

def initialize b1, b2, b3, b4, b5, b6, b7, b8
	@address = [b1, b2, b3, b4, b5, b6, b7, b8]
end

Class Method Details

.from_a(array) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/xbee-ruby/address_64.rb', line 29

def self.from_a array
	if array.length == 8 && array.all? {|x| (0..255).cover? x }
		self.new *array
	else
		raise ArgumentError, "#{array} is not a valid 64-bit address array"
	end
end

.from_s(string) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/xbee-ruby/address_64.rb', line 21

def self.from_s string
	if matcher = /^(\h\h)[^\h]*(\h\h)[^\h]*(\h\h)[^\h]*(\h\h)[^\h]*(\h\h)[^\h]*(\h\h)[^\h]*(\h\h)[^\h]*(\h\h)$/.match(string)
		self.new *(matcher[1..8].map &:hex)
	else
		raise ArgumentError, "#{string} is not a valid 64-bit address string"
	end
end

Instance Method Details

#==(other) ⇒ Object



41
42
43
# File 'lib/xbee-ruby/address_64.rb', line 41

def == other
	to_a == other.to_a
end

#to_aObject



37
38
39
# File 'lib/xbee-ruby/address_64.rb', line 37

def to_a
	@address
end

#to_sObject



45
46
47
# File 'lib/xbee-ruby/address_64.rb', line 45

def to_s
	('%02x' * 8) % @address
end