class RubberBand::Processor
Attributes
command[R]
Public Class Methods
new(input_file, output_file, options = Options.new)
click to toggle source
# File lib/rubberband/processor.rb, line 8 def initialize(input_file, output_file, options = Options.new) @input_file = input_file @output_file = output_file @errors = [] if options.is_a?(String) || options.is_a?(Options) @raw_options = options elsif options.is_a?(Hash) @raw_options = Options.new(options) else raise ArgumentError, "Unknown options format '#{options.class}', should be either EncodingOptions, Hash or String." end end
Public Instance Methods
binary()
click to toggle source
# 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?()
click to toggle source
# 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()
click to toggle source
# 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