Class: Mac::EventMonitor::Monitor
- Inherits:
-
Object
- Object
- Mac::EventMonitor::Monitor
- Defined in:
- lib/mac-event-monitor/monitor.rb
Instance Method Summary collapse
- #add_listener(type, &block) ⇒ Object
-
#initialize ⇒ Monitor
constructor
A new instance of Monitor.
- #receive_event(str) ⇒ Object
- #run(stop_after = nil) ⇒ Object
Constructor Details
#initialize ⇒ Monitor
Returns a new instance of Monitor.
4 5 6 |
# File 'lib/mac-event-monitor/monitor.rb', line 4 def initialize @listeners = {} end |
Instance Method Details
#add_listener(type, &block) ⇒ Object
8 9 10 11 |
# File 'lib/mac-event-monitor/monitor.rb', line 8 def add_listener(type, &block) @listeners[type] ||= [] @listeners[type] << block end |
#receive_event(str) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/mac-event-monitor/monitor.rb', line 17 def receive_event(str) event = Event.create_from_description(str) (@listeners[event.type] || []).each do |block| block.call(event) end end |
#run(stop_after = nil) ⇒ Object
13 14 15 |
# File 'lib/mac-event-monitor/monitor.rb', line 13 def run(stop_after = nil) run_app(stop_after) end |