Class: YoutubeDL::Command
- Inherits:
-
Object
- Object
- YoutubeDL::Command
- Extended by:
- Dry::Configurable
- Defined in:
- lib/youtube_dl/command.rb
Instance Method Summary collapse
- #arguments ⇒ Object
- #config ⇒ Object
-
#initialize(url, **options) ⇒ Command
constructor
A new instance of Command.
- #to_a ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(url, **options) ⇒ Command
Returns a new instance of Command.
21 22 23 24 25 26 27 |
# File 'lib/youtube_dl/command.rb', line 21 def initialize(url, **) @url = url @options = config. .merge() .merge(config.) end |
Instance Method Details
#arguments ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/youtube_dl/command.rb', line 29 def arguments @options.flat_map do |option, value| option = option.to_s.gsub('_', '-') case value when [] then nil when true then "--#{option}" when false then "--no-#{option}" else # Handle array values by repeating the option. # # Example: { paths: ['temp:/tmp', '/complete'] } # Becomes: ['--paths', 'temp:/tmp', '--paths', '/complete'] # # Example: { paths: '/downloads' } # Becomes: ['--paths', '/downloads] [*value].flat_map { |v| ["--#{option}", v] } end end end |
#config ⇒ Object
8 9 10 |
# File 'lib/youtube_dl/command.rb', line 8 def config self.class.config end |
#to_a ⇒ Object
49 50 51 |
# File 'lib/youtube_dl/command.rb', line 49 def to_a [config.executable] + arguments + [@url] end |
#to_s ⇒ Object
53 54 55 |
# File 'lib/youtube_dl/command.rb', line 53 def to_s Shellwords.join(to_a) end |