Class: RubberBand::Processor
- Inherits:
-
Object
- Object
- RubberBand::Processor
- Defined in:
- lib/rubberband/processor.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Instance Method Summary collapse
- #binary ⇒ Object
- #convert_succeeded? ⇒ Boolean
-
#initialize(input_file, output_file, options = Options.new) ⇒ Processor
constructor
A new instance of Processor.
- #run ⇒ Object
Constructor Details
#initialize(input_file, output_file, options = Options.new) ⇒ Processor
Returns a new instance of Processor.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/rubberband/processor.rb', line 8 def initialize(input_file, output_file, = Options.new) @input_file = input_file @output_file = output_file @errors = [] if .is_a?(String) || .is_a?(Options) @raw_options = elsif .is_a?(Hash) @raw_options = Options.new() else raise ArgumentError, "Unknown options format '#{.class}', should be either EncodingOptions, Hash or String." end end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
6 7 8 |
# File 'lib/rubberband/processor.rb', line 6 def command @command end |
Instance Method Details
#binary ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/rubberband/processor.rb', line 22 def binary binary_path = `which rubberband` if $? == 0 binary_path.strip else raise "rubberband binary not found!" end end |
#convert_succeeded? ⇒ Boolean
49 50 51 52 53 54 55 |
# File 'lib/rubberband/processor.rb', line 49 def convert_succeeded? unless File.exists?(@output_file) @errors << "no output file created" return false end true end |
#run ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rubberband/processor.rb', line 31 def run @command = "#{binary} #{@raw_options} '#{Shellwords.escape(@input_file)}' '#{Shellwords.escape(@output_file)}'" output = "" Open3.popen3(@command) do |stdin, stdout, stderr| stderr.each("r") do |line| output << line end end if convert_succeeded? true else errors = @errors.empty? ? "" : " Errors: #{@errors.join(", ")}. " raise "Failed encoding: #{errors}. \nCommand: #{@command}. \nFull output: #{output}" end end |