Class: Mac::EventMonitor::Monitor

Inherits:
Object
  • Object
show all
Defined in:
lib/mac-event-monitor/monitor.rb

Instance Method Summary collapse

Constructor Details

#initializeMonitor

Returns a new instance of Monitor.



4
5
6
7
# File 'lib/mac-event-monitor/monitor.rb', line 4

def initialize
  @listeners     = {}
  @any_listeners = []
end

Instance Method Details

#add_listener(type = nil, &block) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/mac-event-monitor/monitor.rb', line 9

def add_listener(type = nil, &block)
  if type
    @listeners[type] ||= []
    @listeners[type] << block
  else
    @any_listeners << block
  end
end

#receive_event(str, time, screen_height) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/mac-event-monitor/monitor.rb', line 22

def receive_event(str, time, screen_height)
  event = Event.create_from_description(str, time, screen_height)

  (@listeners[event.type] || []).each do |block|
    block.call(event)
  end

  @any_listeners.each do |block|
    block.call(event)
  end
end

#run(stop_after = nil) ⇒ Object



18
19
20
# File 'lib/mac-event-monitor/monitor.rb', line 18

def run(stop_after = nil)
  run_app(stop_after)
end