Class: ScanBeacon::BlueZAdvertiser

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ BlueZAdvertiser



6
7
8
9
10
11
12
13
# File 'lib/scan_beacon/bluez_advertiser.rb', line 6

def initialize(opts = {})
  @device_id = opts[:device_id] || BlueZ.devices.map {|d| d[:device_id]}[0]
  raise "No available devices" if @device_id.nil?
  BlueZ.device_up @device_id
  self.beacon = opts[:beacon]
  self.parser = opts[:parser]
  self.parser ||= BeaconParser.default_parsers.find {|parser| parser.beacon_type == beacon.beacon_types.first}
end

Instance Attribute Details

#adObject

Returns the value of attribute ad.



4
5
6
# File 'lib/scan_beacon/bluez_advertiser.rb', line 4

def ad
  @ad
end

#beaconObject

Returns the value of attribute beacon.



4
5
6
# File 'lib/scan_beacon/bluez_advertiser.rb', line 4

def beacon
  @beacon
end

#parserObject

Returns the value of attribute parser.



4
5
6
# File 'lib/scan_beacon/bluez_advertiser.rb', line 4

def parser
  @parser
end

Instance Method Details

#inspectObject



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

def inspect
  "<BlueZAdvertiser ad=#{@ad.inspect}>"
end

#startObject



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

def start
  BlueZ.start_advertising
end

#stopObject



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

def stop
  BlueZ.stop_advertising
end

#update_adObject



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

def update_ad
  self.ad = @parser.generate_ad(@beacon) if @parser && @beacon
end