class VideoConverter::Command
Attributes
dry_run[RW]
ionice[RW]
nice[RW]
verbose[RW]
command[RW]
Public Class Methods
new(command, params = {})
click to toggle source
# File lib/video_converter/command.rb, line 13 def initialize command, params = {}, safe_keys = [] self.command = command.dup if params.any? params = params.deep_shellescape_values(safe_keys) self.command.gsub!(/%\{(\w+?)\}/) do value = params[$1.to_sym] if value.is_a?(Hash) value.deep_join(' ') else value.to_s end end end raise ArgumentError.new("Command is not parsed '#{self.command}'") if self.command.match(/%{[\w\-.]+}/) self.command = "nice -n #{self.class.nice} #{self.command}" if self.class.nice self.command = "ionice -c 2 -n #{self.class.ionice} #{self.command}" if self.class.ionice end
Public Instance Methods
append(*commands)
click to toggle source
# File lib/video_converter/command.rb, line 49 def append(*commands) self.command = commands.unshift(command).map { |c| "(#{c})" }.join(' && ') self end
capture(params = {})
click to toggle source
# File lib/video_converter/command.rb, line 40 def capture params = {} puts command if params[:verbose] || self.class.verbose `#{command}`.encode('UTF-8', 'binary', :invalid => :replace, :undef => :replace, :replace => '') end
execute(params = {})
click to toggle source
# File lib/video_converter/command.rb, line 31 def execute params = {} puts command if params[:verbose] || self.class.verbose if params[:dry_run] || self.class.dry_run true else system command end end
to_s()
click to toggle source
# File lib/video_converter/command.rb, line 45 def to_s command end