Class: YoutubeDL::Runner
- Inherits:
-
Object
show all
- Defined in:
- lib/youtube_dl/runner.rb
Instance Method Summary
collapse
Constructor Details
#initialize(command, listener: Listener.new) ⇒ Runner
Returns a new instance of Runner.
7
8
9
10
|
# File 'lib/youtube_dl/runner.rb', line 7
def initialize(command, listener: Listener.new)
@command = command
@listener = listener
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, &block) ⇒ Object
37
38
39
40
41
42
|
# File 'lib/youtube_dl/runner.rb', line 37
def method_missing(method, &block)
return super unless method.to_s.start_with?('on_')
event = method.to_s.sub(/^on_/, '').to_sym
on(event, &block)
end
|
Instance Method Details
#call ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/youtube_dl/runner.rb', line 12
def call
parser = OutputParser.new
run(command: @command, parser: parser)
if parser.state.complete?
parser.state.load_and_delete_info_json
@listener.call(:complete, state: parser.state)
elsif parser.state.error?
@listener.call(:error, state: parser.state)
else
@listener.call(:unclear_exit_state, state: parser.state)
end
parser.state
end
|
#on(event, &block) ⇒ Object
28
29
30
31
|
# File 'lib/youtube_dl/runner.rb', line 28
def on(event, &block)
@listener.register(event, &block)
self
end
|
#respond_to_missing?(method) ⇒ Boolean
33
34
35
|
# File 'lib/youtube_dl/runner.rb', line 33
def respond_to_missing?(method, *)
method.to_s.start_with?('on_') || super
end
|