Class: ProximityBeacon::AdvertisedId

Inherits:
GoogleResource show all
Defined in:
lib/proximity_beacon/advertised_id.rb

Instance Method Summary collapse

Methods inherited from GoogleResource

#as_json, camelcase_attr_accessor, #initialize, #to_json, #update

Constructor Details

This class inherits a constructor from ProximityBeacon::GoogleResource

Instance Method Details

#altbeacon_ids=(value) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/proximity_beacon/advertised_id.rb', line 29

def altbeacon_ids=(value)
  self.type = "ALTBEACON"
  uuid = value[0]
  major = value[1].to_i
  minor = value[2].to_i
  bytes = [uuid.gsub("-", "")].pack("H*") + [major].pack("S>") + [minor].pack("S>")
  self.id = Base64.strict_encode64(bytes)
end

#beacon_type_codeObject



46
47
48
49
50
51
52
53
54
55
# File 'lib/proximity_beacon/advertised_id.rb', line 46

def beacon_type_code
  case type
  when "EDDYSTONE"
    3
  when "IBEACON"
    1
  when "ALTBEACON"
    5
  end
end

#bytesObject



5
6
7
# File 'lib/proximity_beacon/advertised_id.rb', line 5

def bytes
  @bytes ||= Base64.decode64(id)
end

#eddystone_ids=(value) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/proximity_beacon/advertised_id.rb', line 38

def eddystone_ids=(value)
  self.type = "EDDYSTONE"
  namespace = value[0]
  instance = value[1]
  bytes = [namespace + instance].pack("H*")
  self.id = Base64.strict_encode64(bytes)
end

#ibeacon_ids=(value) ⇒ Object



20
21
22
23
24
25
26
27
# File 'lib/proximity_beacon/advertised_id.rb', line 20

def ibeacon_ids=(value)
  self.type = "IBEACON"
  uuid = value[0]
  major = value[1].to_i
  minor = value[2].to_i
  bytes = [uuid.gsub("-", "")].pack("H*") + [major].pack("S>") + [minor].pack("S>")
  self.id = Base64.strict_encode64(bytes)
end

#idsObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/proximity_beacon/advertised_id.rb', line 9

def ids
  case type
  when "EDDYSTONE"
    [id_field(0..9), id_field(10..15)]
  when "IBEACON"
    [id_field(0..15), id_field(16..17), id_field(18..19)]
  when "ALTBEACON"
    [id_field(0..15), id_field(16..17), id_field(18..19)]
  end
end

#inspectObject



61
62
63
# File 'lib/proximity_beacon/advertised_id.rb', line 61

def inspect
  "#<AdvertisedId type=#{type} ids=#{ids}>"
end

#to_beacon_nameObject



57
58
59
# File 'lib/proximity_beacon/advertised_id.rb', line 57

def to_beacon_name
  "beacons/#{beacon_type_code}!#{bytes.unpack("H*")[0]}"
end