class Typingpool::Filer::Files::Audio

Handler for collection of Filer::Audio instances. Does everything Filer::Files does, plus can batch convert to mp3 an can merge the Filer::Audio instances into a single audio file, provided they are in mp3 format.

Public Class Methods

new(files) click to toggle source

Constructor. Takes an array of Filer or Filer subclass instances.

# File lib/typingpool/filer/files/audio.rb, line 12
def initialize(files)
  @files = files.map{|file| self.file(file.path) }
end

Public Instance Methods

file(path) click to toggle source
# File lib/typingpool/filer/files/audio.rb, line 16
def file(path)
  Filer::Audio.new(path)
end
merge(into_file) click to toggle source

Merge Filer::Audio instances into a single new file, provided they are all in mp3 format.

==== Params
into_file

Filer or Filer subclass instance corresponding to

the location of the new, merged file that should be created.

==== Returns
Filer::Audio instance corresponding to the new, merged file.
# File lib/typingpool/filer/files/audio.rb, line 49
def merge(into_file)
  raise Error::Argument, "No files to merge" if self.to_a.empty?
  if self.count > 1
    Utility.system_quietly('mp3wrap', into_file, *self.to_a)
    written = File.join(into_file.dir, "#{File.basename(into_file.path, '.*') }_MP3WRAP.mp3")
    FileUtils.mv(written, into_file)
  else
    FileUtils.cp(self.first, into_file)
  end
  self.file(into_file.path)
end
to_mp3(dest_dir, bitrate=nil) { |file| ... } click to toggle source

Batch convert Filer::Audio instances to mp3 format.

==== Params
[dest_dir] Filer::Dir instance corresponding to directory
           into which mp3 file versions will be created.
[bitrate]  See documentation for Filer::Audio#bitrate.
==== Returns
Filer::Files::Audio instance corresponding to new mp3
versions of the original files or, in the case where the
original file was already in mp3 format, corresponding to
the original files themselves.
# File lib/typingpool/filer/files/audio.rb, line 30
def to_mp3(dest_dir, bitrate=nil)
  mp3s = self.map do |file|
    if file.mp3?
      file
    else
      yield(file) if block_given?
      file.to_mp3(dest_dir.file("#{File.basename(file.path, '.*') }.mp3"), bitrate)
    end
  end
  self.class.new(mp3s)
end