Class: Paperclip::WavMp3

Inherits:
Processor
  • Object
show all
Defined in:
lib/wav-mp3.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options = {}, attachment = nil) ⇒ WavMp3

Returns a new instance of WavMp3.



7
8
9
10
11
12
13
14
# File 'lib/wav-mp3.rb', line 7

def initialize file, options = {}, attachment = nil
  super
  @file           = file
  @params         = options[:params]
  @current_format = File.extname(@file.path)
  @basename       = File.basename(@file.path, @current_format)
  @format         = options[:format]
end

Instance Attribute Details

#fileObject

Returns the value of attribute file.



5
6
7
# File 'lib/wav-mp3.rb', line 5

def file
  @file
end

#formatObject

Returns the value of attribute format.



5
6
7
# File 'lib/wav-mp3.rb', line 5

def format
  @format
end

#paramsObject

Returns the value of attribute params.



5
6
7
# File 'lib/wav-mp3.rb', line 5

def params
  @params
end

Instance Method Details

#makeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/wav-mp3.rb', line 16

def make
  src = @file
  dst = Tempfile.new([@basename, @format ? ".#{@format}" : ''])
  begin
    parameters = []
    parameters << @params
    parameters << ":source"
    parameters << ":dest"
    parameters = parameters.flatten.compact.join(" ").strip.squeeze(" ")
    success = Paperclip.run("lame", parameters, :source => "#{File.expand_path(src.path)}",:dest => File.expand_path(dst.path))
  rescue PaperclipCommandLineError => e
    raise PaperclipError, "There was an error converting #{@basename} to mp3"
  end
  dst
end