Class: Mac::EventMonitor::Event
- Inherits:
-
Object
- Object
- Mac::EventMonitor::Event
- Includes:
- JsonSerializable
- Defined in:
- lib/mac-event-monitor/event.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#location ⇒ Object
readonly
Returns the value of attribute location.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
- .create_from_description(description, time, screen_height) ⇒ Object
- .parse_location(location_as_str) ⇒ Object
Instance Method Summary collapse
- #data ⇒ Object
-
#initialize(type, time, location) ⇒ Event
constructor
A new instance of Event.
Methods included from JsonSerializable
Constructor Details
#initialize(type, time, location) ⇒ Event
Returns a new instance of Event.
54 55 56 57 58 |
# File 'lib/mac-event-monitor/event.rb', line 54 def initialize(type, time, location) @type = type.to_sym @time = time @location = location end |
Instance Attribute Details
#location ⇒ Object (readonly)
Returns the value of attribute location.
6 7 8 |
# File 'lib/mac-event-monitor/event.rb', line 6 def location @location end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
6 7 8 |
# File 'lib/mac-event-monitor/event.rb', line 6 def time @time end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
6 7 8 |
# File 'lib/mac-event-monitor/event.rb', line 6 def type @type end |
Class Method Details
.create_from_description(description, time, screen_height) ⇒ Object
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 43 44 45 46 47 |
# File 'lib/mac-event-monitor/event.rb', line 9 def create_from_description(description, time, screen_height) _, *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 location = parse_location(attrs[:loc]) location.y = screen_height - location.y case attrs[:type] when 'LMouseUp' MouseEvent.new(:mouse_up, time, location, :left) when 'RMouseUp' MouseEvent.new(:mouse_up, time, location, :right) when 'OMouseUp' MouseEvent.new(:mouse_up, time, location, :other) when 'LMouseDown' MouseEvent.new(:mouse_down, time, location, :left) when 'RMouseDown' MouseEvent.new(:mouse_down, time, location, :right) when 'OMouseDown' MouseEvent.new(:mouse_down, time, location, :other) when 'MouseMoved' MouseEvent.new(:mouse_move, time, location, nil) when 'LMouseDragged' MouseEvent.new(:mouse_drag, time, location, :left) when 'RMouseDragged' MouseEvent.new(:mouse_drag, time, location, :right) when 'OMouseDragged' MouseEvent.new(:mouse_drag, time, location, :other) when 'KeyDown' KeyboardEvent.new(:key_down, time, location, attrs[:keyCode], attrs[:flags]) when 'KeyUp' KeyboardEvent.new(:key_up, time, location, attrs[:keyCode], attrs[:flags]) end end |
Instance Method Details
#data ⇒ Object
60 61 62 |
# File 'lib/mac-event-monitor/event.rb', line 60 def data [type, time, location] end |