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.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/attached/processor/audio.rb', line 23 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.
12 13 14 |
# File 'lib/attached/processor/audio.rb', line 12 def @attachment end |
#extension ⇒ Object (readonly)
Returns the value of attribute extension.
10 11 12 |
# File 'lib/attached/processor/audio.rb', line 10 def extension @extension end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/attached/processor/audio.rb', line 9 def path @path end |
#preset ⇒ Object (readonly)
Returns the value of attribute preset.
11 12 13 |
# File 'lib/attached/processor/audio.rb', line 11 def preset @preset end |
Instance Method Details
#process ⇒ Object
Helper function for calling processors.
Usage:
self.process
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/attached/processor/audio.rb', line 48 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.
37 38 39 |
# File 'lib/attached/processor/audio.rb', line 37 def redirect ">/dev/null 2>&1" if File.exist?("/dev/null") end |