Sha256: 09bc0b3239455513f69385ff5e4439b7b6dde1d513cbca34c81e649789796ebf

Contents?: true

Size: 723 Bytes

Versions: 1

Compression:

Stored size: 723 Bytes

Contents

module Mac
  module EventMonitor
    class Monitor
      def initialize
        @listeners     = {}
        @any_listeners = []
      end

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

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

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mac-event-monitor-0.2.0 lib/mac-event-monitor/monitor.rb