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.



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

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.



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

def offset_x
  @offset_x
end

#offset_yObject

Returns the value of attribute offset_y.



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

def offset_y
  @offset_y
end

#query_stringObject

Returns the value of attribute query_string.



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

def query_string
  @query_string
end

#releaseObject

Returns the value of attribute release.



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

def release
  @release
end

#timeObject

Returns the value of attribute time.



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

def time
  @time
end

#waitObject

Returns the value of attribute wait.



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

def wait
  @wait
end

#xObject

Returns the value of attribute x.



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

def x
  @x
end

#yObject

Returns the value of attribute y.



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

def y
  @y
end

Instance Method Details

#+(touch) ⇒ Object



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

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



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

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



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

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

#offset=(offset) ⇒ Object



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

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

#to_hashObject



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

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



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

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