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
# File 'lib/scan_beacon/beacon.rb', line 8

def initialize(opts={})
  @ids = opts[:ids]
  @power = opts[:power]
  @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

#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

#powerObject

Returns the value of attribute power.



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

def power
  @power
end

Instance Method Details

#==(obj) ⇒ Object



15
16
17
# File 'lib/scan_beacon/beacon.rb', line 15

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

#add_rssi(val) ⇒ Object



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

def add_rssi(val)
  @rssis << val
end

#add_type(val) ⇒ Object



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

def add_type(val)
  @beacon_types << val
end

#inspectObject



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

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

#majorObject



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

def major
  ids[1]
end

#minorObject



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

def minor
  ids[2]
end

#rssiObject



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

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

#uuidObject



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

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