Class: ICuke::Simulate::Events::Touch
- Defined in:
- lib/icuke/simulate.rb
Constant Summary collapse
- GSEventHand =
3001
- GSTouchDown =
1
- GSTouchUp =
6
- GSTouchMoved =
2
- TYPE =
{ :down => GSTouchDown, :up => GSTouchUp, :moved => GSTouchMoved }.freeze
Instance Attribute Summary collapse
-
#paths ⇒ Object
Returns the value of attribute paths.
-
#type ⇒ Object
Returns the value of attribute type.
Attributes inherited from Event
#event_time, #hold_for, #options
Instance Method Summary collapse
- #averageX ⇒ Object
- #averageY ⇒ Object
-
#initialize(type, paths, options = {}) ⇒ Touch
constructor
A new instance of Touch.
- #to_json(*a) ⇒ Object
Methods inherited from Event
Constructor Details
#initialize(type, paths, options = {}) ⇒ Touch
Returns a new instance of Touch.
41 42 43 44 45 46 |
# File 'lib/icuke/simulate.rb', line 41 def initialize(type, paths, = {}) super() @type = type @paths = paths end |
Instance Attribute Details
#paths ⇒ Object
Returns the value of attribute paths.
39 40 41 |
# File 'lib/icuke/simulate.rb', line 39 def paths @paths end |
#type ⇒ Object
Returns the value of attribute type.
39 40 41 |
# File 'lib/icuke/simulate.rb', line 39 def type @type end |
Instance Method Details
#averageX ⇒ Object
48 49 50 |
# File 'lib/icuke/simulate.rb', line 48 def averageX paths.inject(0) { |s,p| s + p[0] } / paths.size end |
#averageY ⇒ Object
52 53 54 |
# File 'lib/icuke/simulate.rb', line 52 def averageY paths.inject(0) { |s,p| s + p[1] } / paths.size end |
#to_json(*a) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/icuke/simulate.rb', line 56 def to_json(*a) { 'Type' => GSEventHand, 'Time' => event_time, 'WindowLocation' => { 'X' => averageX, 'Y' => averageY }, 'Data' => { 'Delta' => { 'X' => paths.size, 'Y' => paths.size }, 'Type' => TYPE[type], 'Paths' => paths.map { |p| { 'Location' => { 'X' => p[0], 'Y' => p[1] }, 'Size' => { 'X' => 1.0, 'Y' => 1.0 } } } } }.to_json(*a) end |