Class: ScanBeacon::Beacon
- Inherits:
-
Object
- Object
- ScanBeacon::Beacon
- Defined in:
- lib/scan_beacon/beacon.rb,
lib/scan_beacon/beacon/field.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Field
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.
-
#rssis ⇒ Object
Returns the value of attribute rssis.
-
#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 = opts[: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 |
#rssis ⇒ Object
Returns the value of attribute rssis.
6 7 8 |
# File 'lib/scan_beacon/beacon.rb', line 6 def rssis @rssis 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
47 48 49 |
# File 'lib/scan_beacon/beacon.rb', line 47 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
51 52 53 |
# File 'lib/scan_beacon/beacon.rb', line 51 def inspect "<Beacon ids=#{@ids.join(",")} rssi=#{rssi}, scans=#{ad_count}, power=#{@power}, type=\"#{@beacon_types.to_a.join(",")}\">" end |
#major ⇒ Object
39 40 41 |
# File 'lib/scan_beacon/beacon.rb', line 39 def major ids[1].to_i end |
#minor ⇒ Object
43 44 45 |
# File 'lib/scan_beacon/beacon.rb', line 43 def minor ids[2].to_i 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 37 |
# File 'lib/scan_beacon/beacon.rb', line 34 def uuid id0 = ids[0].to_s "#{id0[0..7]}-#{id0[8..11]}-#{id0[12..15]}-#{id0[16..19]}-#{id0[20..-1]}".upcase end |