Class: VideoConverter::Command
Class Attribute Summary collapse
-
.dry_run ⇒ Object
Returns the value of attribute dry_run.
-
.ionice ⇒ Object
Returns the value of attribute ionice.
-
.nice ⇒ Object
Returns the value of attribute nice.
-
.verbose ⇒ Object
Returns the value of attribute verbose.
Instance Attribute Summary collapse
-
#command ⇒ Object
Returns the value of attribute command.
Instance Method Summary collapse
- #append(*commands) ⇒ Object
- #capture(params = {}) ⇒ Object
- #execute(params = {}) ⇒ Object
-
#initialize(command, params = {}, safe_keys = []) ⇒ Command
constructor
A new instance of Command.
- #to_s ⇒ Object
Constructor Details
#initialize(command, params = {}, safe_keys = []) ⇒ Command
Returns a new instance of Command.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# 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 |
Class Attribute Details
.dry_run ⇒ Object
Returns the value of attribute dry_run.
6 7 8 |
# File 'lib/video_converter/command.rb', line 6 def dry_run @dry_run end |
.ionice ⇒ Object
Returns the value of attribute ionice.
6 7 8 |
# File 'lib/video_converter/command.rb', line 6 def ionice @ionice end |
.nice ⇒ Object
Returns the value of attribute nice.
6 7 8 |
# File 'lib/video_converter/command.rb', line 6 def nice @nice end |
.verbose ⇒ Object
Returns the value of attribute verbose.
6 7 8 |
# File 'lib/video_converter/command.rb', line 6 def verbose @verbose end |
Instance Attribute Details
#command ⇒ Object
Returns the value of attribute command.
11 12 13 |
# File 'lib/video_converter/command.rb', line 11 def command @command end |
Instance Method Details
#append(*commands) ⇒ Object
49 50 51 52 |
# File 'lib/video_converter/command.rb', line 49 def append(*commands) self.command = commands.unshift(command).map { |c| "(#{c})" }.join(' && ') self end |
#capture(params = {}) ⇒ Object
40 41 42 43 |
# 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 = {}) ⇒ Object
31 32 33 34 35 36 37 38 |
# 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 ⇒ Object
45 46 47 |
# File 'lib/video_converter/command.rb', line 45 def to_s command end |