Class: Calabash::Android::Gestures::Touch

Inherits:
Object
  • Object
show all
Defined in:
lib/calabash-android/gestures.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(touch) ⇒ Touch

Returns a new instance of Touch.



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File 'lib/calabash-android/gestures.rb', line 242

def initialize(touch)
  if touch.is_a?(Touch)
    touch = touch.to_hash
  end

  touch[:offset] ||= {}
  touch[:offset_x] ||= touch[:offset][:x]
  touch[:offset_y] ||= touch[:offset][:y]

  @x = touch[:x]
  @y = touch[:y]
  @offset_x = touch[:offset_x] || 0
  @offset_y = touch[:offset_y] || 0
  @wait = touch[:wait] || 0
  @time = touch[:time] || 0
  @release = touch[:release].nil? ? false : touch[:release]
  @query_string = touch[:query_string]
end

Instance Attribute Details

#offset_xObject

Returns the value of attribute offset_x.



240
241
242
# File 'lib/calabash-android/gestures.rb', line 240

def offset_x
  @offset_x
end

#offset_yObject

Returns the value of attribute offset_y.



240
241
242
# File 'lib/calabash-android/gestures.rb', line 240

def offset_y
  @offset_y
end

#query_stringObject

Returns the value of attribute query_string.



240
241
242
# File 'lib/calabash-android/gestures.rb', line 240

def query_string
  @query_string
end

#releaseObject

Returns the value of attribute release.



240
241
242
# File 'lib/calabash-android/gestures.rb', line 240

def release
  @release
end

#timeObject

Returns the value of attribute time.



240
241
242
# File 'lib/calabash-android/gestures.rb', line 240

def time
  @time
end

#waitObject

Returns the value of attribute wait.



240
241
242
# File 'lib/calabash-android/gestures.rb', line 240

def wait
  @wait
end

#xObject

Returns the value of attribute x.



240
241
242
# File 'lib/calabash-android/gestures.rb', line 240

def x
  @x
end

#yObject

Returns the value of attribute y.



240
241
242
# File 'lib/calabash-android/gestures.rb', line 240

def y
  @y
end

Instance Method Details

#+(touch) ⇒ Object



282
283
284
285
286
287
288
289
# File 'lib/calabash-android/gestures.rb', line 282

def +(touch)
  hash = to_hash
  hash[:x] += touch.x
  hash[:y] += touch.y
  hash[:offset_x] += touch.offset_x
  hash[:offset_y] += touch.offset_y
  Touch.new(hash)
end

#-(touch) ⇒ Object



291
292
293
294
295
296
297
298
# File 'lib/calabash-android/gestures.rb', line 291

def -(touch)
  hash = to_hash
  hash[:x] -= touch.x
  hash[:y] -= touch.y
  hash[:offset_x] -= touch.offset_x
  hash[:offset_y] -= touch.offset_y
  Touch.new(hash)
end

#merge(touch) ⇒ Object



261
262
263
# File 'lib/calabash-android/gestures.rb', line 261

def merge(touch)
  Touch.new(to_hash.merge(touch.to_hash))
end

#offset=(offset) ⇒ Object



300
301
302
303
# File 'lib/calabash-android/gestures.rb', line 300

def offset=(offset)
  @offset_x = offset[:x]
  @offset_y = offset[:y]
end

#to_hashObject



265
266
267
268
269
270
271
272
273
274
275
276
# File 'lib/calabash-android/gestures.rb', line 265

def to_hash
  {
      x: @x,
      y: @y,
      offset_x: @offset_x || 0,
      offset_y: @offset_y || 0,
      wait: @wait.to_f,
      time: @time.to_f,
      release: @release,
      query_string: @query_string
  }
end

#to_json(object = Hash) ⇒ Object



278
279
280
# File 'lib/calabash-android/gestures.rb', line 278

def to_json(object = Hash)
  to_hash.to_json(object)
end