Module: Pouf
- Defined in:
- lib/pouf.rb
Constant Summary collapse
- SOUNDS_DIR =
File.("~/.pouf/sounds")
Class Method Summary collapse
-
.add(name, fname) ⇒ Object
Actions ##.
- .alias2filename(name) ⇒ Object
- .filename2alias(fname) ⇒ Object
- .init ⇒ Object
- .list ⇒ Object
- .mv(from, to) ⇒ Object
- .play(*aliases) ⇒ Object
- .play_cmd ⇒ Object
- .play_sound(filename) ⇒ Object
- .rm(*names) ⇒ Object
- .version ⇒ Object
Class Method Details
.add(name, fname) ⇒ Object
Actions ##
49 50 51 52 53 54 |
# File 'lib/pouf.rb', line 49 def add name, fname fname =~ /.+\.(\w+)$/ ext = $1 FileUtils.cp fname, "#{SOUNDS_DIR}/#{name}.#{ext}" end |
.alias2filename(name) ⇒ Object
37 38 39 40 |
# File 'lib/pouf.rb', line 37 def alias2filename name fns = Dir["#{SOUNDS_DIR}/#{name}.*"] fns.first if fns end |
.filename2alias(fname) ⇒ Object
42 43 44 45 |
# File 'lib/pouf.rb', line 42 def filename2alias fname fname =~ /(?:.*?\/)?(.+)\.\w+$/ $1 end |
.init ⇒ Object
56 57 58 |
# File 'lib/pouf.rb', line 56 def init FileUtils.mkdir_p SOUNDS_DIR end |
.list ⇒ Object
60 61 62 63 64 |
# File 'lib/pouf.rb', line 60 def list Dir.entries(SOUNDS_DIR).select{ |f| f !~ /^\./ }.map do |f| filename2alias f end end |
.mv(from, to) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/pouf.rb', line 66 def mv from, to f1 = alias2filename from f2 = f1.sub(/\/#{from}\./, "/#{to}.") FileUtils.mv(f1, f2) if f1 and f2 end |
.play(*aliases) ⇒ Object
73 74 75 76 77 78 |
# File 'lib/pouf.rb', line 73 def play *aliases aliases.each do |a| fname = alias2filename a play_sound fname if fname end end |
.play_cmd ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'lib/pouf.rb', line 15 def play_cmd return ENV['POUF_CMD'].split(' ') if ENV['POUF_CMD'] case RUBY_PLATFORM when /darwin/ then ['afplay'] when /linux/ then ['mpg123', '-q'] else nil end end |
.play_sound(filename) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/pouf.rb', line 24 def play_sound filename return unless filename cmd = play_cmd if cmd system *cmd, filename else puts 'pouf is unsupported for your platform for now' end end |
.rm(*names) ⇒ Object
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/pouf.rb', line 80 def rm *names names.each do |n| fs = alias2filename n if fs FileUtils.rm fs else puts "Warning: No sound found for '#{n}'." end end end |
.version ⇒ Object
11 12 13 |
# File 'lib/pouf.rb', line 11 def version '0.1.1' end |