Class: Media::Command::Converter
- Inherits:
-
Object
- Object
- Media::Command::Converter
- Defined in:
- lib/media/command/converter.rb
Instance Attribute Summary collapse
-
#inputs ⇒ Object
Returns the value of attribute inputs.
-
#options(value = nil) ⇒ Object
(also: #options=)
Returns the value of attribute options.
-
#outputs ⇒ Object
Returns the value of attribute outputs.
Instance Method Summary collapse
- #add_input(url, &block) ⇒ Object (also: #input)
- #add_output(url, &block) ⇒ Object (also: #output)
- #call(&blk) ⇒ Object
-
#initialize(args = {}, &block) ⇒ Converter
constructor
A new instance of Converter.
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(args = {}, &block) ⇒ Converter
Returns a new instance of Converter.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/media/command/converter.rb', line 11 def initialize(args={}, &block) @options = Array args.fetch(:options, []) @inputs = Array args.fetch(:inputs, []) @outputs = Array args.fetch(:outputs, []) @cmd = args.fetch(:cmd, 'ffmpeg') @subshell = args.fetch(:subshell, Subshell) @progress = args.fetch(:progress, Progress) block.arity < 1 ? instance_eval(&block) : block.call(self) if block_given? end |
Instance Attribute Details
#inputs ⇒ Object
Returns the value of attribute inputs.
9 10 11 |
# File 'lib/media/command/converter.rb', line 9 def inputs @inputs end |
#options(value = nil) ⇒ Object Also known as: options=
Returns the value of attribute options.
9 10 11 |
# File 'lib/media/command/converter.rb', line 9 def @options end |
#outputs ⇒ Object
Returns the value of attribute outputs.
9 10 11 |
# File 'lib/media/command/converter.rb', line 9 def outputs @outputs end |
Instance Method Details
#add_input(url, &block) ⇒ Object Also known as: input
54 55 56 |
# File 'lib/media/command/converter.rb', line 54 def add_input(url, &block) @inputs << Input.new(url: url, &block) end |
#add_output(url, &block) ⇒ Object Also known as: output
59 60 61 |
# File 'lib/media/command/converter.rb', line 59 def add_output(url, &block) @outputs << Output.new(url: url, &block) end |
#call(&blk) ⇒ Object
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/media/command/converter.rb', line 23 def call(&blk) progress = @progress.new process = @subshell.new(cmd: to_a).call do |line| progress.update(line, &blk) end progress.complete(&blk) if process.success? process end |
#to_a ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/media/command/converter.rb', line 34 def to_a [ @cmd, ( + ).map(&:to_a), inputs.map(&:to_a), outputs.map(&:to_a) ].flatten end |
#to_s ⇒ Object
43 44 45 |
# File 'lib/media/command/converter.rb', line 43 def to_s to_a.join(' ') end |