Class: ScanBeacon::Beacon
- Inherits:
-
Object
- Object
- ScanBeacon::Beacon
- Defined in:
- lib/scan_beacon/beacon.rb
Instance Attribute Summary collapse
-
#beacon_types ⇒ Object
Returns the value of attribute beacon_types.
-
#ids ⇒ Object
Returns the value of attribute ids.
-
#mac ⇒ Object
Returns the value of attribute mac.
-
#power ⇒ Object
Returns the value of attribute power.
Instance Method Summary collapse
- #==(obj) ⇒ Object
- #add_rssi(val) ⇒ Object
- #add_type(val) ⇒ Object
-
#initialize(opts = {}) ⇒ Beacon
constructor
A new instance of Beacon.
- #inspect ⇒ Object
- #major ⇒ Object
- #minor ⇒ Object
- #rssi ⇒ Object
- #uuid ⇒ Object
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_types ⇒ Object
Returns the value of attribute beacon_types.
6 7 8 |
# File 'lib/scan_beacon/beacon.rb', line 6 def beacon_types @beacon_types end |
#ids ⇒ Object
Returns the value of attribute ids.
6 7 8 |
# File 'lib/scan_beacon/beacon.rb', line 6 def ids @ids end |
#mac ⇒ Object
Returns the value of attribute mac.
6 7 8 |
# File 'lib/scan_beacon/beacon.rb', line 6 def mac @mac end |
#power ⇒ Object
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 |
#inspect ⇒ Object
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 |
#major ⇒ Object
35 36 37 |
# File 'lib/scan_beacon/beacon.rb', line 35 def major ids[1] end |
#minor ⇒ Object
39 40 41 |
# File 'lib/scan_beacon/beacon.rb', line 39 def minor ids[2] end |
#rssi ⇒ Object
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 |
#uuid ⇒ Object
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 |