Class: ScanBeacon::Beacon

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Beacon

Returns a new instance of Beacon.



8
9
10
11
12
13
14
15
16
# File 'lib/scan_beacon/beacon.rb', line 8

def initialize(opts={})
  @ids = opts[:ids] || []
  @data = opts[:data] || []
  @power = opts[:power]
  @mfg_id = opts[:mfg_id]
  @service_uuid = opts[:service_uuid]
  @beacon_types = Set.new [opts[:beacon_type]]
  @rssis = []
end

Instance Attribute Details

#beacon_typesObject

Returns the value of attribute beacon_types.



6
7
8
# File 'lib/scan_beacon/beacon.rb', line 6

def beacon_types
  @beacon_types
end

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/scan_beacon/beacon.rb', line 6

def data
  @data
end

#idsObject

Returns the value of attribute ids.



6
7
8
# File 'lib/scan_beacon/beacon.rb', line 6

def ids
  @ids
end

#macObject

Returns the value of attribute mac.



6
7
8
# File 'lib/scan_beacon/beacon.rb', line 6

def mac
  @mac
end

#mfg_idObject

Returns the value of attribute mfg_id.



6
7
8
# File 'lib/scan_beacon/beacon.rb', line 6

def mfg_id
  @mfg_id
end

#powerObject

Returns the value of attribute power.



6
7
8
# File 'lib/scan_beacon/beacon.rb', line 6

def power
  @power
end

#service_uuidObject

Returns the value of attribute service_uuid.



6
7
8
# File 'lib/scan_beacon/beacon.rb', line 6

def service_uuid
  @service_uuid
end

Instance Method Details

#==(obj) ⇒ Object



18
19
20
# File 'lib/scan_beacon/beacon.rb', line 18

def ==(obj)
  obj.is_a?(Beacon) && obj.mac == @mac && obj.ids == @ids
end

#ad_countObject



46
47
48
# File 'lib/scan_beacon/beacon.rb', line 46

def ad_count
  @rssis.size
end

#add_rssi(val) ⇒ Object



22
23
24
# File 'lib/scan_beacon/beacon.rb', line 22

def add_rssi(val)
  @rssis << val
end

#add_type(val) ⇒ Object



26
27
28
# File 'lib/scan_beacon/beacon.rb', line 26

def add_type(val)
  @beacon_types << val
end

#inspectObject



50
51
52
# File 'lib/scan_beacon/beacon.rb', line 50

def inspect
  "<Beacon ids=#{@ids.join(",")} rssi=#{rssi}, scans=#{ad_count}, power=#{@power}, type=\"#{@beacon_types.to_a.join(",")}\">"
end

#majorObject



38
39
40
# File 'lib/scan_beacon/beacon.rb', line 38

def major
  ids[1]
end

#minorObject



42
43
44
# File 'lib/scan_beacon/beacon.rb', line 42

def minor
  ids[2]
end

#rssiObject



30
31
32
# File 'lib/scan_beacon/beacon.rb', line 30

def rssi
  @rssis.inject(0) {|sum, el| sum += el} / @rssis.size.to_f
end

#uuidObject



34
35
36
# File 'lib/scan_beacon/beacon.rb', line 34

def uuid
  "#{ids[0][0..7]}-#{ids[0][8..11]}-#{ids[0][12..15]}-#{ids[0][16..19]}-#{ids[0][20..-1]}".upcase
end