Module: RVideo::Tools::AbstractTool::InstanceMethods
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#raw_result ⇒ Object
readonly
Returns the value of attribute raw_result.
Instance Method Summary collapse
-
#execute ⇒ Object
Execute the command and parse the result.
- #initialize(raw_command, options = {}) ⇒ Object
-
#interpolate_variables(raw_command) ⇒ Object
Look for variables surrounded by $, and interpolate with either variables passed in the options hash, or special methods provided by the tool class (e.g. “$original_fps$” with ffmpeg).
-
#matched_variable(match) ⇒ Object
Strip the $s.
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
17 18 19 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 17 def command @command end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 17 def @options end |
#raw_result ⇒ Object (readonly)
Returns the value of attribute raw_result.
17 18 19 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 17 def raw_result @raw_result end |
Instance Method Details
#execute ⇒ Object
Execute the command and parse the result.
62 63 64 65 66 67 68 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 62 def execute final_command = "#{@command} 2>&1" Transcoder.logger.info("\nExecuting Command: #{final_command}\n") @raw_result = `#{final_command}` Transcoder.logger.info("Result: \n#{@raw_result}") parse_result(@raw_result) end |
#initialize(raw_command, options = {}) ⇒ Object
19 20 21 22 23 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 19 def initialize(raw_command, = {}) @raw_command = raw_command @options = HashWithIndifferentAccess.new() @command = interpolate_variables(raw_command) end |
#interpolate_variables(raw_command) ⇒ Object
Look for variables surrounded by $, and interpolate with either variables passed in the options hash, or special methods provided by the tool class (e.g. “$original_fps$” with ffmpeg).
$foo$ should match $foo or $foo$ or $foo$ should not
33 34 35 36 37 38 39 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 33 def interpolate_variables(raw_command) raw_command.scan(/[^\\]\$[-_a-zA-Z]+\$/).each do |match| match.strip! raw_command.gsub!(match, matched_variable(match)) end raw_command.gsub("\\$", "$") end |
#matched_variable(match) ⇒ Object
Strip the $s. First, look for a supplied option that matches the variable name. If one is not found, look for a method that matches. If not found, raise ParameterError exception.
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/rvideo/tools/abstract_tool.rb', line 47 def matched_variable(match) variable_name = match.gsub("$","") if @options.key?(variable_name) @options[variable_name] || "" elsif self.respond_to? variable_name self.send(variable_name) else raise TranscoderError::ParameterError, "command is looking for the #{variable_name} parameter, but it was not provided. (Command: #{@raw_command})" end end |