Class: Mac::EventMonitor::Event
- Inherits:
-
Object
- Object
- Mac::EventMonitor::Event
- Defined in:
- lib/mac-event-monitor/event.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(type) ⇒ Event
constructor
A new instance of Event.
Constructor Details
#initialize(type) ⇒ Event
Returns a new instance of Event.
45 46 47 |
# File 'lib/mac-event-monitor/event.rb', line 45 def initialize(type) @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
4 5 6 |
# File 'lib/mac-event-monitor/event.rb', line 4 def type @type end |
Class Method Details
.create_from_description(description) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mac-event-monitor/event.rb', line 7 def create_from_description(description) _, *atts_as_string = description.split(/ +/) attrs = (atts_as_string.join(' ') + ' ').scan(/([^=]+)=([^=]+) (?=\w?)/).inject({}) do |result, pair| name, value = pair result[name.to_sym] = value result end case attrs[:type] when 'LMouseUp' MouseEvent.new(:mouse_up, attrs[:loc], :left) when 'RMouseUp' MouseEvent.new(:mouse_up, attrs[:loc], :right) when 'OMouseUp' MouseEvent.new(:mouse_up, attrs[:loc], :other) when 'LMouseDown' MouseEvent.new(:mouse_down, attrs[:loc], :left) when 'RMouseDown' MouseEvent.new(:mouse_down, attrs[:loc], :right) when 'OMouseDown' MouseEvent.new(:mouse_down, attrs[:loc], :other) when 'MouseMoved' MouseEvent.new(:mouse_move, attrs[:loc], nil) when 'LMouseDragged' MouseEvent.new(:mouse_drag, attrs[:loc], :left) when 'RMouseDragged' MouseEvent.new(:mouse_drag, attrs[:loc], :right) when 'OMouseDragged' MouseEvent.new(:mouse_drag, attrs[:loc], :other) when 'KeyDown' KeyboardEvent.new(:key_down, attrs[:keyCode], attrs[:flags]) when 'KeyUp' KeyboardEvent.new(:key_up, attrs[:keyCode], attrs[:flags]) end end |