class Sounder::SoundGroup

Attributes

sounds[R]

Public Class Methods

new(sounds_hsh) click to toggle source
# 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

Public Instance Methods

play(name) click to toggle source
# File lib/sounder/sound_group.rb, line 12
def play name
  sound = sounds.fetch(fuzzy_find name) { raise UnknownSoundError }
  sound.play
end
random() click to toggle source
# File lib/sounder/sound_group.rb, line 17
def random
  @sounds.map do |_,sound|
    sound
  end.sample.play
end
usage() click to toggle source
# 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

Private Instance Methods

fuzzy_find(name) click to toggle source
# File lib/sounder/sound_group.rb, line 34
def fuzzy_find name
  @sounds.keys.select { |sn| sn.downcase.include? name.downcase }.first
end