Class: YoutubeDL::Listener
- Inherits:
-
Object
- Object
- YoutubeDL::Listener
- Defined in:
- lib/youtube_dl/listener.rb
Instance Method Summary collapse
- #call(event, state:, line: nil) ⇒ Object
-
#initialize ⇒ Listener
constructor
A new instance of Listener.
- #register(event, &block) ⇒ Object
Constructor Details
#initialize ⇒ Listener
Returns a new instance of Listener.
3 4 5 |
# File 'lib/youtube_dl/listener.rb', line 3 def initialize @callbacks = Hash.new { |h, k| h[k] = [] } end |
Instance Method Details
#call(event, state:, line: nil) ⇒ Object
7 8 9 10 11 |
# File 'lib/youtube_dl/listener.rb', line 7 def call(event, state:, line: nil) (@callbacks[event] + @callbacks[:any]).each do |cb| cb.call(state: state, line: line) end end |
#register(event, &block) ⇒ Object
13 14 15 |
# File 'lib/youtube_dl/listener.rb', line 13 def register(event, &block) @callbacks[event] << block end |