Class: Attached::Processor::Audio
- Defined in:
- lib/attached/processor/audio.rb
Instance Attribute Summary collapse
-
#attachment ⇒ Object
readonly
Returns the value of attribute attachment.
-
#extension ⇒ Object
readonly
Returns the value of attribute extension.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#preset ⇒ Object
readonly
Returns the value of attribute preset.
Attributes inherited from Base
Instance Method Summary collapse
-
#initialize(file, options = {}, attachment = nil) ⇒ Audio
constructor
Create a processor.
-
#process ⇒ Object
Helper function for calling processors.
-
#redirect ⇒ Object
Redirect output path.
Methods inherited from Base
Constructor Details
#initialize(file, options = {}, attachment = nil) ⇒ Audio
Create a processor.
Parameters:
-
file - The file to be processed.
-
options - The options to be applied to the processing.
-
attachment - The attachment the processor is being run for.
21 22 23 24 25 26 27 |
# File 'lib/attached/processor/audio.rb', line 21 def initialize(file, = {}, = nil) super @path = self.file.path @preset = [:preset] @extension = [:extension] @extension ||= self..extension end |
Instance Attribute Details
#attachment ⇒ Object (readonly)
Returns the value of attribute attachment.
11 12 13 |
# File 'lib/attached/processor/audio.rb', line 11 def @attachment end |
#extension ⇒ Object (readonly)
Returns the value of attribute extension.
9 10 11 |
# File 'lib/attached/processor/audio.rb', line 9 def extension @extension end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
8 9 10 |
# File 'lib/attached/processor/audio.rb', line 8 def path @path end |
#preset ⇒ Object (readonly)
Returns the value of attribute preset.
10 11 12 |
# File 'lib/attached/processor/audio.rb', line 10 def preset @preset end |
Instance Method Details
#process ⇒ Object
Helper function for calling processors.
Usage:
self.process
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/attached/processor/audio.rb', line 41 def process result = Tempfile.new(["", self.extension]) result.binmode begin parameters = [] parameters << "--preset #{self.preset}" if self.preset parameters << self.path parameters << result.path parameters = parameters.join(" ").squeeze(" ") `lame #{parameters} #{redirect}` raise Errno::ENOENT if $?.exitstatus == 127 rescue Errno::ENOENT raise "command 'lame' not found: ensure LAME is installed" end unless $?.exitstatus == 0 raise Attached::Processor::Error, "must be an audio file" end return result end |
#redirect ⇒ Object
Redirect output path.
31 32 33 |
# File 'lib/attached/processor/audio.rb', line 31 def redirect ">/dev/null 2>&1" if File.exist?("/dev/null") end |