sounder 1.0.2 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8df9741d168eeba2db6c05ee1c6d1d9532ecd663
4
- data.tar.gz: 1398cba28a6d833eb95fa07869db03492d9aec5e
3
+ metadata.gz: 8db35dd8172a5ff154d11235b32aa4a5d9b70432
4
+ data.tar.gz: 1eef09bfe03073ef9ea443b63b269361819fb883
5
5
  SHA512:
6
- metadata.gz: 3e08ffcd9195685638dffec8ca961151067f31c0b0f0df7a916bbb1c7ecf1988d6a8ec1a637ea4b4537e9047f1aadedc53125b9c01c0abfdf7b45b0cf4e88428
7
- data.tar.gz: 9c99e7251d3e7147ee47dc2d3c089d6870d79e84c59710d13aa43afea55463cb8a806ce7c92c49f74f1597ed5e935c419729aabe7501c7e8121511bd9ee94c6c
6
+ metadata.gz: 2c5ddc4f23231824dabbf3e6c7d7521c7162bf59b2b0980e16f0eaf6f0fffeca1e28a4d5b4dc16db9a0102d4c7fccd959fa8ee7664ed38a93ea8762e0c9dbd11
7
+ data.tar.gz: da9b1a6b2ec679b514be1fba75024fc55c4b798152fa6b0a5a1ae15dd493649aba3a363b210c8c7f9db75a021fa8d812c042984e7cfaef6f306244d14462c65d
@@ -2,6 +2,7 @@ require "sounder/version"
2
2
  require "sounder/system"
3
3
  require "sounder/sound"
4
4
  require "sounder/sound_group"
5
+ require "sounder/soundboard"
5
6
 
6
7
  module Sounder
7
8
  def self.play path
@@ -9,4 +10,5 @@ module Sounder
9
10
  end
10
11
 
11
12
  class UnknownSoundError < ArgumentError; end
13
+ class RootNotSetError < ArgumentError; end
12
14
  end
@@ -0,0 +1,67 @@
1
+ module Sounder
2
+ class Soundboard
3
+ attr_reader :version_info
4
+ attr_accessor :root
5
+
6
+ def initialize sounds:, version_info: "Sounder Soundboard", root: nil
7
+ @soundgroup = {}
8
+ @version_info = version_info
9
+ @sounds = sounds
10
+ @root = root
11
+ end
12
+
13
+ def run args
14
+ case
15
+ when random?(args) then soundgroup.random
16
+ when help?(args) then puts usage
17
+ when sound?(args) then play_sound(args.join ' ')
18
+ else
19
+ puts usage
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def soundgroup
26
+ @soundgroup[root] ||= begin
27
+ names_and_paths = Hash[@sounds.map { |name, file| [name, get_path(file)] }]
28
+ SoundGroup.new names_and_paths
29
+ end
30
+ end
31
+
32
+ def play_sound sound_name
33
+ soundgroup.play sound_name
34
+ rescue UnknownSoundError
35
+ unknown_sound_message
36
+ end
37
+
38
+ def unknown_sound_message
39
+ puts "Error: \"#{sound_name}\" does not match a known sound"
40
+ puts usage
41
+ end
42
+
43
+ def get_path file
44
+ raise RootNotSetError.new("You must set a support directory first") unless root
45
+ File.join root, "#{file}.m4a"
46
+ end
47
+
48
+ def sound? args
49
+ not args.empty?
50
+ end
51
+
52
+ def help? args
53
+ args.size == 1 && %w[-h --help].include?(args.first)
54
+ end
55
+
56
+ def random? args
57
+ args.size == 1 && args.first == 'random'
58
+ end
59
+
60
+ def usage
61
+ usage = soundgroup.usage.map { |line| " #{line}" }
62
+ usage.unshift version_info, "Usage:"
63
+ usage.join "\n"
64
+ end
65
+
66
+ end
67
+ end
@@ -1,3 +1,3 @@
1
1
  module Sounder
2
- VERSION = "1.0.2"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -16,7 +16,7 @@ describe Sounder do
16
16
  end
17
17
  it "creates sound objects" do
18
18
  sounds.each do |name, file|
19
- Sounder::Sound.should_receive(:new).with file
19
+ expect(Sounder::Sound).to receive(:new).with file
20
20
  end
21
21
  Sounder::SoundGroup.new sounds
22
22
  end
@@ -26,14 +26,14 @@ describe Sounder do
26
26
  it "plays a sound corresponding to the argument passed in" do
27
27
  group = Sounder::SoundGroup.new sounds
28
28
  sound_b = group.sounds.fetch "sound_b"
29
- sound_b.should_receive(:play)
29
+ expect(sound_b).to receive(:play)
30
30
  group.play "sound_b"
31
31
  end
32
32
 
33
33
  it "fuzzy matches the sound name" do
34
34
  group = Sounder::SoundGroup.new sounds
35
35
  sound_b = group.sounds.fetch "sound_b"
36
- sound_b.should_receive(:play)
36
+ expect(sound_b).to receive(:play)
37
37
  group.play "b"
38
38
  end
39
39
 
@@ -46,7 +46,7 @@ describe Sounder do
46
46
  describe '#random' do
47
47
  it "plays a random sound" do
48
48
  group = Sounder::SoundGroup.new sounds
49
- Sounder::Sound.any_instance.should_receive :play
49
+ expect_any_instance_of(Sounder::Sound).to receive :play
50
50
  group.random
51
51
  end
52
52
  end
@@ -54,9 +54,9 @@ describe Sounder do
54
54
  describe '#usage' do
55
55
  it "returns usage info in a string" do
56
56
  group = Sounder::SoundGroup.new sounds
57
- group.usage.should include "random (picks a random sound)"
58
- group.usage.should include " sound_a"
59
- group.usage.should include " sound_b"
57
+ expect(group.usage).to include "random (picks a random sound)"
58
+ expect(group.usage).to include " sound_a"
59
+ expect(group.usage).to include " sound_b"
60
60
  end
61
61
  end
62
62
  end
@@ -1,26 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Sounder do
4
-
5
- describe Sounder::Sound do
6
- let(:sound) { Sounder::Sound.new 'fake/file.m4a' }
7
- describe 'initialization' do
8
- it "saves the file as a path" do
9
- sound.file.should == 'fake/file.m4a'
10
- end
3
+ describe Sounder::Sound do
4
+ let(:sound) { Sounder::Sound.new 'fake/file.m4a' }
5
+ describe 'initialization' do
6
+ it "saves the file as a path" do
7
+ expect(sound.file).to eq 'fake/file.m4a'
11
8
  end
9
+ end
12
10
 
13
- describe '#play' do
14
- it "plays a file" do
15
- sound.should_receive(:system).with %{/usr/bin/afplay "fake/file.m4a" &}
16
- sound.play
17
- end
18
- it "is not super insecure" do
19
- bad_sound = Sounder::Sound.new '";echo doing bad things;"'
20
- bad_sound.should_receive(:system).with %{/usr/bin/afplay \"\\\"\\;echo\\ doing\\ bad\\ things\\;\\\"\" &}
21
- bad_sound.play
22
- end
11
+ describe '#play' do
12
+ it "plays a file" do
13
+ expect(sound).to receive(:system).with %{/usr/bin/afplay "fake/file.m4a" &}
14
+ sound.play
15
+ end
16
+ it "is not super insecure" do
17
+ bad_sound = Sounder::Sound.new '";echo doing bad things;"'
18
+ expect(bad_sound).to receive(:system).with %{/usr/bin/afplay \"\\\"\\;echo\\ doing\\ bad\\ things\\;\\\"\" &}
19
+ bad_sound.play
23
20
  end
24
21
  end
25
-
26
22
  end
@@ -0,0 +1,45 @@
1
+ require 'pry'
2
+ require 'spec_helper'
3
+
4
+ describe Sounder::Soundboard do
5
+ let(:sounds) { { 'sound name' => 'path' } }
6
+ subject(:soundboard) { Sounder::Soundboard.new sounds: sounds, root: root }
7
+
8
+ describe '#run' do
9
+ context "when root isn't set" do
10
+ let(:root) {}
11
+ it "raises an error if the root isn't set" do
12
+ expect { soundboard.run(['test']) }.to raise_error Sounder::RootNotSetError
13
+ end
14
+ end
15
+
16
+ context "when root is set" do
17
+ let(:root) { 'some/path' }
18
+ it "plays a random sound when given random" do
19
+ expect_any_instance_of(Sounder::SoundGroup).to receive :random
20
+ soundboard.run %w[random]
21
+ end
22
+ it "displays the usage if --help option is given" do
23
+ expect(soundboard).to receive(:usage).and_return []
24
+ soundboard.run %w[--help]
25
+ end
26
+ it "displays the usage if -h option is given" do
27
+ expect(soundboard).to receive(:usage).and_return []
28
+ soundboard.run %w[-h]
29
+ end
30
+ it "displays the usage if no option is given" do
31
+ expect(soundboard).to receive(:usage).and_return []
32
+ soundboard.run []
33
+ end
34
+ it "plays a sound if a valid sound name is given" do
35
+ expect_any_instance_of(Sounder::SoundGroup).to receive :play
36
+ soundboard.run %w[sound name]
37
+ end
38
+ it "displays usage if an invalid sound name is given" do
39
+ allow_any_instance_of(Sounder::SoundGroup).to receive(:play).and_raise Sounder::UnknownSoundError
40
+ expect(soundboard).to receive :unknown_sound_message
41
+ soundboard.run %w[invalid name]
42
+ end
43
+ end
44
+ end
45
+ end
@@ -1,22 +1,20 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Sounder do
4
-
5
4
  describe Sounder::System do
6
5
  describe '.set_volume' do
7
6
  it "uses system to set the volume" do
8
- Sounder::System.should_receive(:system).with %{osascript -e "set volume 7.0"}
7
+ expect(Sounder::System).to receive(:system).with %{osascript -e "set volume 7.0"}
9
8
  Sounder::System.set_volume 100
10
9
  end
11
10
  it "converts the number to base 7" do
12
- Sounder::System.should_receive(:system).with %{osascript -e "set volume 3.5"}
11
+ expect(Sounder::System).to receive(:system).with %{osascript -e "set volume 3.5"}
13
12
  Sounder::System.set_volume 50
14
13
  end
15
14
  it "doesn't make the call if it isn't given a number" do
16
- Sounder::System.should_not_receive(:system)
15
+ expect(Sounder::System).to_not receive(:system)
17
16
  Sounder::System.set_volume "something bad"
18
17
  end
19
18
  end
20
19
  end
21
-
22
20
  end
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Sounder do
4
4
  describe '#play' do
5
5
  it "plays a sound" do
6
- Sounder::Sound.any_instance.should_receive(:system).with %{/usr/bin/afplay "fake/file.m4a" &}
6
+ expect_any_instance_of(Sounder::Sound).to receive(:system).with %{/usr/bin/afplay "fake/file.m4a" &}
7
7
  Sounder.play 'fake/file.m4a'
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sounder
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Zaninovich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-06 00:00:00.000000000 Z
11
+ date: 2014-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: Play sounds on your Mac
@@ -59,7 +59,7 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
62
+ - ".gitignore"
63
63
  - Gemfile
64
64
  - LICENSE.txt
65
65
  - README.md
@@ -67,11 +67,13 @@ files:
67
67
  - lib/sounder.rb
68
68
  - lib/sounder/sound.rb
69
69
  - lib/sounder/sound_group.rb
70
+ - lib/sounder/soundboard.rb
70
71
  - lib/sounder/system.rb
71
72
  - lib/sounder/version.rb
72
73
  - sounder.gemspec
73
74
  - spec/sounder/sound_group_spec.rb
74
75
  - spec/sounder/sound_spec.rb
76
+ - spec/sounder/soundboard_spec.rb
75
77
  - spec/sounder/system_spec.rb
76
78
  - spec/sounder_spec.rb
77
79
  - spec/spec_helper.rb
@@ -85,23 +87,24 @@ require_paths:
85
87
  - lib
86
88
  required_ruby_version: !ruby/object:Gem::Requirement
87
89
  requirements:
88
- - - '>='
90
+ - - ">="
89
91
  - !ruby/object:Gem::Version
90
92
  version: '0'
91
93
  required_rubygems_version: !ruby/object:Gem::Requirement
92
94
  requirements:
93
- - - '>='
95
+ - - ">="
94
96
  - !ruby/object:Gem::Version
95
97
  version: '0'
96
98
  requirements: []
97
99
  rubyforge_project:
98
- rubygems_version: 2.0.5
100
+ rubygems_version: 2.2.2
99
101
  signing_key:
100
102
  specification_version: 4
101
103
  summary: Play sounds on your Mac
102
104
  test_files:
103
105
  - spec/sounder/sound_group_spec.rb
104
106
  - spec/sounder/sound_spec.rb
107
+ - spec/sounder/soundboard_spec.rb
105
108
  - spec/sounder/system_spec.rb
106
109
  - spec/sounder_spec.rb
107
110
  - spec/spec_helper.rb