walkon 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e98fa4a3f793072e126e54bb7885cc9ad4a11509
4
- data.tar.gz: a613f716836c62e95d919db026bd3101395ffe62
3
+ metadata.gz: 3dd89fe98df5e1a8190fb561b248585b550b5b64
4
+ data.tar.gz: aaaca1c64f5c8f14e32cbe42e6d482cfe567d462
5
5
  SHA512:
6
- metadata.gz: 94c888a21f894d3ec03066389834954bd53dc9da3bcff4b280e7d192b78a707a5a0066bbeb8d08adce83bd7305c4dfdb0b327c2a0c7fab3c121886767c1c00c5
7
- data.tar.gz: 5b840b4c8e37048f83b8589ce8fc8d746737d182df1f05a6f866276bfba8a85dfdf446b8485359d35eece2b803eea504bda23009ad3ad4bd2e610ff76caa9bf5
6
+ metadata.gz: 30cc38a8b631df17479412c7ee84bd0c633bc14a9d855b70f8f0c6f806508f364375f74a7b3864aae9f8516b1f6d89319df1864355c26b0541d21b7fde4ab97a
7
+ data.tar.gz: e8d491fc4c29125883e785b532b0a6fa9f611e161be14af43d07e4195a08405ed5ef28674da45988fd90299052bcd0b4746157d855e1cffb17061e4bed1286ec
@@ -25,22 +25,17 @@ module Walkon
25
25
  loop { check_for_devices }
26
26
  end
27
27
 
28
+ private
28
29
  def check_for_devices
29
- scanned_devices.each do |mac_address|
30
- unless self.devices.include? mac_address
31
- device = Device.new mac_address
32
- play_entrance_music_for device
33
- self.devices << Device.new(mac_address)
34
- end
35
- end
30
+ @devices = scanned_device_ess_ids.reject { |ess_id|
31
+ devices.include? ess_id
32
+ }.map { |ess_id|
33
+ Device.play! ess_id
34
+ }
36
35
  end
37
36
 
38
- def scanned_devices
37
+ def scanned_device_ess_ids
39
38
  HciTool.scan
40
39
  end
41
-
42
- def play_entrance_music_for device
43
- device.entrance_music.play if device.has_entrance_music?
44
- end
45
40
  end
46
41
  end
@@ -1,14 +1,26 @@
1
1
  require 'walkon/entrance_music'
2
2
 
3
- # Represents a single Bluetooth device in the building.
3
+ # Represents a single Bluetooth device in the building. When HciTool
4
+ # detects the device on the network, it plays the entrance music.
4
5
 
5
6
  module Walkon
6
7
  class Device
7
- attr_reader :mac_address, :entrance_music
8
+ attr_reader :ess_id, :entrance_music
8
9
 
9
- def initialize with_mac_address
10
- @mac_address = with_mac_address
11
- @entrance_music = EntranceMusic.new self
10
+ def initialize from_ess_id
11
+ @ess_id = from_ess_id
12
+ @entrance_music = EntranceMusic.new from_ess_id
13
+ end
14
+
15
+ def self.play! for_ess_id
16
+ device = new for_ess_id
17
+ device.play
18
+ device
19
+ end
20
+
21
+ def play
22
+ return unless has_entrance_music?
23
+ entrance_music.play
12
24
  end
13
25
 
14
26
  def has_entrance_music?
@@ -1,14 +1,11 @@
1
- require 'walkon/device'
2
-
3
1
  # Finds and plays the entrance music for a given device.
4
2
 
5
3
  module Walkon
6
4
  class EntranceMusic
7
- attr_reader :device, :filename
5
+ attr_reader :filename
8
6
 
9
- def initialize from_device
10
- @device = from_device
11
- @filename = "#{prefix}/#{@device.mac_address}.mp3"
7
+ def initialize with_file_name
8
+ @filename = "#{prefix}/#{with_file_name}.mp3"
12
9
  end
13
10
 
14
11
  def exists?
@@ -18,11 +15,13 @@ module Walkon
18
15
  alias present? exists?
19
16
 
20
17
  def play
21
- return false unless exists?
22
- `xmms #{filename}`
18
+ present? and play_track
19
+ end
20
+
21
+ def play_track
22
+ `xmms #{filename}` == ''
23
23
  end
24
24
 
25
- private
26
25
  def prefix
27
26
  if Walkon.env == 'test'
28
27
  File.expand_path "../../../spec/fixtures/music", __FILE__
@@ -13,17 +13,23 @@ module Walkon
13
13
  end
14
14
 
15
15
  def scan
16
- @results = scan_results.reduce([]) do |collection, line|
17
- line.scan FOR_MAC_ADDRESS do |mac_address|
18
- collection << mac_address.first
16
+ @results += scan_results_ess_ids
17
+ @results = @results.uniq
18
+ @results
19
+ end
20
+
21
+ private
22
+ def scan_results_ess_ids
23
+ each_line = /\A(..:..:..:..:..:..)\s(.*)\Z/
24
+ scan_results.reduce([]) do |collection, line|
25
+ line.scan each_line do |(mac_addr,ess_id)|
26
+ collection << ess_id.strip
19
27
  end
20
28
 
21
29
  collection
22
30
  end
23
31
  end
24
32
 
25
- private
26
- FOR_MAC_ADDRESS = /(..:..:..:..:..:..)/
27
33
  def scan_results
28
34
  `hcitool scan`.split "\n"
29
35
  end
@@ -1,3 +1,3 @@
1
1
  module Walkon
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -3,22 +3,28 @@ require 'walkon/daemon'
3
3
 
4
4
  module Walkon
5
5
  describe Daemon do
6
- context "when a new device is detected" do
7
- let(:mac_address) { "00:A1:5D:AB:B2:E9" }
6
+ it "runs the loop" do
7
+ expect(subject).to respond_to(:run)
8
+ end
8
9
 
10
+ it "starts from the command line" do
11
+ expect(subject.class).to respond_to(:start)
12
+ end
13
+
14
+ context "when a new device is detected" do
9
15
  before do
10
- subject.stub(:scanned_devices) { [mac_address] }
11
- subject.stub(:play_entrance_music_for) { |device| true }
12
- subject.check_for_devices
16
+ allow(HciTool).to receive(:scan).and_return ['iPhone5']
17
+ allow(Device).to receive(:play!).and_return Device.new('iPhone5')
18
+ subject.send :check_for_devices
13
19
  end
14
20
 
15
- it "adds the sample mac address to devices" do
16
- expect(subject.devices.map(&:mac_address)).to include(mac_address)
21
+ it "adds the sample ess id to devices" do
22
+ expect(subject.devices.map(&:ess_id)).to include('iPhone5')
17
23
  end
18
24
 
19
25
  it "plays device's entrance music" do
20
26
  expect(subject.devices).to_not be_empty
21
- device = subject.devices.select { |dev| dev.mac_address == mac_address }.first
27
+ device = subject.devices.first
22
28
  expect(device).to_not be_nil
23
29
  expect(device).to have_entrance_music
24
30
  end
@@ -3,14 +3,25 @@ require 'walkon/device'
3
3
 
4
4
  module Walkon
5
5
  describe Device do
6
- subject { Device.new '00:A1:5D:AB:B2:E9' }
6
+ subject { Device.new 'iPhone5' }
7
7
 
8
- it "requires a mac address for identification" do
9
- expect(subject.mac_address).to_not be_nil
8
+ it "requires a ess id for identification" do
9
+ expect(subject.ess_id).to_not be_nil
10
+ expect(subject.ess_id).to eq('iPhone5')
10
11
  end
11
12
 
12
- it "uses mac address to find entrance music in configured dir" do
13
+ it "uses ess id to find entrance music in configured dir" do
13
14
  expect(subject).to have_entrance_music
14
15
  end
16
+
17
+ it "delegates to the entrance music to play" do
18
+ allow(subject.entrance_music).to receive(:play_track).and_return true
19
+ expect(subject.play).to eq(true)
20
+ end
21
+
22
+ it "does not play when no entrance music" do
23
+ allow(subject).to receive(:has_entrance_music?).and_return false
24
+ expect(subject.play).to_not eq(true)
25
+ end
15
26
  end
16
27
  end
@@ -3,24 +3,43 @@ require 'walkon/entrance_music'
3
3
 
4
4
  module Walkon
5
5
  describe EntranceMusic do
6
- let(:mac_address) { "00:A1:5D:AB:B2:E9" }
7
- let(:device) do
8
- dev = double :device
9
- dev.stub(:mac_address) { mac_address }
10
- dev
11
- end
12
- subject { EntranceMusic.new device }
6
+ subject { EntranceMusic.new 'iPhone5' }
13
7
 
14
- before do
15
- subject.stub(:play) { "" }
16
- end
8
+ context "when the mp3 file is found" do
9
+ before do
10
+ allow(File).to receive(:exists?).with(subject.filename).and_return true
11
+ end
12
+
13
+ it "is considered to be present" do
14
+ expect(subject).to be_present
15
+ end
16
+
17
+ it "is considered to be existant" do
18
+ expect(subject).to be_exists
19
+ end
17
20
 
18
- it "finds an mp3 file to play" do
19
- expect(subject).to be_present
21
+ it "runs an xmms command to play the track" do
22
+ allow(subject).to receive(:play_track).and_return true
23
+ expect(subject.play).to eq(true)
24
+ end
20
25
  end
21
26
 
22
- it "plays the mp3 file if found" do
23
- expect(subject.play).to be_true
27
+ context "when the mp3 file is not found" do
28
+ before do
29
+ allow(File).to receive(:exists?).with(subject.filename).and_return false
30
+ end
31
+
32
+ it "is considered not present" do
33
+ expect(subject).to_not be_present
34
+ end
35
+
36
+ it "is considered non-existant" do
37
+ expect(subject).to_not be_exists
38
+ end
39
+
40
+ it "will not run the xmms command to play track" do
41
+ expect(subject.play).to eq(false)
42
+ end
24
43
  end
25
44
  end
26
45
  end
@@ -2,25 +2,24 @@ require 'spec_helper'
2
2
 
3
3
  module Walkon
4
4
  describe HciTool do
5
- let(:mac_address) { "00:A1:5D:AB:B2:E9" }
6
- let(:sample_output) do
7
- %(
8
- Scanning....
9
- #{mac_address} Nokia 6600
10
- ).split("\n")
5
+ let :results do
6
+ [
7
+ 'Scanning...',
8
+ '00:A1:5D:AB:B2:E9 iPhone5'
9
+ ]
11
10
  end
12
11
 
13
12
  before do
14
- subject.stub(:scan_results) { sample_output }
13
+ allow(subject).to receive(:scan_results).and_return results
15
14
  end
16
15
 
17
16
  it "starts with no results" do
18
17
  expect(subject.results).to be_empty
19
18
  end
20
19
 
21
- it "finds mac addresses with a scan" do
20
+ it "finds ess ids with a scan" do
22
21
  expect(subject.scan).to_not be_empty
23
- expect(subject.results.first).to eq(mac_address)
22
+ expect(subject.results.first).to eq('iPhone5')
24
23
  end
25
24
  end
26
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: walkon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Scott
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-29 00:00:00.000000000 Z
11
+ date: 2014-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,7 +81,7 @@ files:
81
81
  - lib/walkon/hci_tool.rb
82
82
  - lib/walkon/version.rb
83
83
  - lib/walkon.rb
84
- - spec/fixtures/music/00:A1:5D:AB:B2:E9.mp3
84
+ - spec/fixtures/music/iPhone5.mp3
85
85
  - spec/spec_helper.rb
86
86
  - spec/walkon/daemon_spec.rb
87
87
  - spec/walkon/device_spec.rb
@@ -115,7 +115,7 @@ signing_key:
115
115
  specification_version: 4
116
116
  summary: Play your entrance music
117
117
  test_files:
118
- - spec/fixtures/music/00:A1:5D:AB:B2:E9.mp3
118
+ - spec/fixtures/music/iPhone5.mp3
119
119
  - spec/spec_helper.rb
120
120
  - spec/walkon/daemon_spec.rb
121
121
  - spec/walkon/device_spec.rb