Class: Sox::CommandBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/sox/command_builder.rb

Overview

Builds the sox shell command from input files, an output file, options and effects.

Examples:

builder = Sox::CommandBuilder.new(['in1.mp3', 'in2.ogg'], 'out.wav',
  {:combine => :mix},
  {:rate => 44100, :channels => 2}
)
builder.build  # => "sox --combine mix in1.mp3 in2.ogg out.wav rate 44100 channels 2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input_files, output_file, options = {}, effects = {}) ⇒ CommandBuilder

Returns a new instance of CommandBuilder.

Parameters:

  • input_files (Array<Sox::File>)
  • output_file (Sox::File)
  • options (Hash{Symbol => Symbol}) (defaults to: {})
  • effects (Hash{Symbol => Symbol}) (defaults to: {})


18
19
20
21
22
23
# File 'lib/sox/command_builder.rb', line 18

def initialize(input_files, output_file, options = {}, effects = {})
  @input_files = input_files
  @output_file = output_file
  @options     = options
  @effects     = effects
end

Instance Attribute Details

#effectsObject

Returns the value of attribute effects.



12
13
14
# File 'lib/sox/command_builder.rb', line 12

def effects
  @effects
end

#input_filesObject

Returns the value of attribute input_files.



12
13
14
# File 'lib/sox/command_builder.rb', line 12

def input_files
  @input_files
end

#optionsObject

Returns the value of attribute options.



12
13
14
# File 'lib/sox/command_builder.rb', line 12

def options
  @options
end

#output_fileObject

Returns the value of attribute output_file.



12
13
14
# File 'lib/sox/command_builder.rb', line 12

def output_file
  @output_file
end

Instance Method Details

#buildString

Build shell command with all arguments and options.

Returns:

  • (String)


28
29
30
31
32
33
34
35
# File 'lib/sox/command_builder.rb', line 28

def build
  [ Sox::SOX_COMMAND,
    build_options(@options),
    build_input_files,
    build_file(@output_file),
    build_effects
  ].flatten.join(' ')
end