module Radbeacon::Utils

Public Instance Methods

bytes_to_major_minor(bytes) click to toggle source
# File lib/radbeacon/utils.rb, line 24
def bytes_to_major_minor(bytes)
  bytes.delete(' ').to_i(16)
end
bytes_to_power(bytes) click to toggle source
# File lib/radbeacon/utils.rb, line 32
def bytes_to_power(bytes)
  bytes.to_i(16) - 256
end
bytes_to_text(bytes) click to toggle source
# File lib/radbeacon/utils.rb, line 8
def bytes_to_text(bytes)
  [bytes.delete(' ')].pack('H*').gsub(/\x00/,'')
end
bytes_to_uuid(bytes) click to toggle source
# 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) click to toggle source
# File lib/radbeacon/utils.rb, line 20
def major_minor_to_bytes(value)
  sprintf("%04x", value.to_i)
end
pin_to_bytes(pin) click to toggle source
# File lib/radbeacon/utils.rb, line 36
def pin_to_bytes(pin)
  pin.unpack('H*')[0]
end
power_to_bytes(power) click to toggle source
# File lib/radbeacon/utils.rb, line 28
def power_to_bytes(power)
  sprintf("%x", power.to_i + 256)
end
text_to_bytes(text) click to toggle source
# File lib/radbeacon/utils.rb, line 4
def text_to_bytes(text)
  text.unpack('H*')[0]
end
uuid_to_bytes(uuid) click to toggle source
# File lib/radbeacon/utils.rb, line 12
def uuid_to_bytes(uuid)
  uuid.gsub(/-/, '')
end