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.
-
#data ⇒ Object
Returns the value of attribute data.
-
#ids ⇒ Object
Returns the value of attribute ids.
-
#mac ⇒ Object
Returns the value of attribute mac.
-
#mfg_id ⇒ Object
Returns the value of attribute mfg_id.
-
#power ⇒ Object
Returns the value of attribute power.
-
#service_uuid ⇒ Object
Returns the value of attribute service_uuid.
Instance Method Summary collapse
- #==(obj) ⇒ Object
- #ad_count ⇒ 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 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_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 |
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/scan_beacon/beacon.rb', line 6 def data @data 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 |
#mfg_id ⇒ Object
Returns the value of attribute mfg_id.
6 7 8 |
# File 'lib/scan_beacon/beacon.rb', line 6 def mfg_id @mfg_id end |
#power ⇒ Object
Returns the value of attribute power.
6 7 8 |
# File 'lib/scan_beacon/beacon.rb', line 6 def power @power end |
#service_uuid ⇒ Object
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_count ⇒ Object
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 |
#inspect ⇒ Object
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 |
#major ⇒ Object
38 39 40 |
# File 'lib/scan_beacon/beacon.rb', line 38 def major ids[1] end |
#minor ⇒ Object
42 43 44 |
# File 'lib/scan_beacon/beacon.rb', line 42 def minor ids[2] end |
#rssi ⇒ Object
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 |
#uuid ⇒ Object
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 |