Module: Radbeacon::Utils
- Included in:
- Usb
- Defined in:
- lib/radbeacon/utils.rb
Instance Method Summary collapse
- #bytes_to_major_minor(bytes) ⇒ Object
- #bytes_to_power(bytes) ⇒ Object
- #bytes_to_text(bytes) ⇒ Object
- #bytes_to_uuid(bytes) ⇒ Object
- #major_minor_to_bytes(value) ⇒ Object
- #pin_to_bytes(pin) ⇒ Object
- #power_to_bytes(power) ⇒ Object
- #text_to_bytes(text) ⇒ Object
- #uuid_to_bytes(uuid) ⇒ Object
Instance Method Details
#bytes_to_major_minor(bytes) ⇒ Object
24 25 26 |
# File 'lib/radbeacon/utils.rb', line 24 def bytes_to_major_minor(bytes) bytes.delete(' ').to_i(16) end |
#bytes_to_power(bytes) ⇒ Object
32 33 34 |
# File 'lib/radbeacon/utils.rb', line 32 def bytes_to_power(bytes) bytes.to_i(16) - 256 end |
#bytes_to_text(bytes) ⇒ Object
8 9 10 |
# File 'lib/radbeacon/utils.rb', line 8 def bytes_to_text(bytes) [bytes.delete(' ')].pack('H*').gsub(/\x00/,'') end |
#bytes_to_uuid(bytes) ⇒ Object
16 17 18 |
# File 'lib/radbeacon/utils.rb', line 16 def bytes_to_uuid(bytes) bytes.delete(' ').sub(/([a-fA-F0-9]{8})([a-fA-F0-9]{4})([a-fA-F0-9]{4})([a-fA-F0-9]{4})([a-fA-F0-9]{12})/, '\1-\2-\3-\4-\5').upcase end |
#major_minor_to_bytes(value) ⇒ Object
20 21 22 |
# File 'lib/radbeacon/utils.rb', line 20 def major_minor_to_bytes(value) sprintf("%04x", value.to_i) end |
#pin_to_bytes(pin) ⇒ Object
36 37 38 |
# File 'lib/radbeacon/utils.rb', line 36 def pin_to_bytes(pin) pin.unpack('H*')[0] end |
#power_to_bytes(power) ⇒ Object
28 29 30 |
# File 'lib/radbeacon/utils.rb', line 28 def power_to_bytes(power) sprintf("%x", power.to_i + 256) end |
#text_to_bytes(text) ⇒ Object
4 5 6 |
# File 'lib/radbeacon/utils.rb', line 4 def text_to_bytes(text) text.unpack('H*')[0] end |
#uuid_to_bytes(uuid) ⇒ Object
12 13 14 |
# File 'lib/radbeacon/utils.rb', line 12 def uuid_to_bytes(uuid) uuid.gsub(/-/, '') end |