Class: Sounder::SoundGroup
- Inherits:
-
Object
- Object
- Sounder::SoundGroup
- Defined in:
- lib/sounder/sound_group.rb
Instance Attribute Summary collapse
-
#sounds ⇒ Object
readonly
Returns the value of attribute sounds.
Instance Method Summary collapse
-
#initialize(sounds_hsh) ⇒ SoundGroup
constructor
A new instance of SoundGroup.
- #play(name) ⇒ Object
- #random ⇒ Object
- #usage ⇒ Object
Constructor Details
#initialize(sounds_hsh) ⇒ SoundGroup
Returns a new instance of SoundGroup.
5 6 7 8 9 10 |
# File 'lib/sounder/sound_group.rb', line 5 def initialize sounds_hsh @sounds = {} sounds_hsh.each do |name, file| @sounds[name.to_s] = Sounder::Sound.new file end end |
Instance Attribute Details
#sounds ⇒ Object (readonly)
Returns the value of attribute sounds.
3 4 5 |
# File 'lib/sounder/sound_group.rb', line 3 def sounds @sounds end |
Instance Method Details
#play(name) ⇒ Object
12 13 14 15 |
# File 'lib/sounder/sound_group.rb', line 12 def play name sound = sounds.fetch(fuzzy_find name) { raise UnknownSoundError } sound.play end |
#random ⇒ Object
17 18 19 20 21 |
# File 'lib/sounder/sound_group.rb', line 17 def random @sounds.map do |_,sound| sound end.sample.play end |
#usage ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/sounder/sound_group.rb', line 23 def usage [ "random (picks a random sound)", "<sound name> (it will fuzzy match the name)", "Available sounds:" ] + @sounds.keys.map do |sound| " #{sound}" end end |