Class: Fusuma::Swipe

Inherits:
Object
  • Object
show all
Defined in:
lib/fusuma/swipe.rb

Overview

vector data

Constant Summary collapse

BASE_THERESHOLD =
20
BASE_INTERVAL =
0.5

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x, y) ⇒ Swipe

Returns a new instance of Swipe.



7
8
9
10
# File 'lib/fusuma/swipe.rb', line 7

def initialize(x, y)
  @x = x
  @y = y
end

Class Attribute Details

.last_timeObject (readonly)

Returns the value of attribute last_time.



48
49
50
# File 'lib/fusuma/swipe.rb', line 48

def last_time
  @last_time
end

Instance Attribute Details

#xObject (readonly)

Returns the value of attribute x.



11
12
13
# File 'lib/fusuma/swipe.rb', line 11

def x
  @x
end

#yObject (readonly)

Returns the value of attribute y.



11
12
13
# File 'lib/fusuma/swipe.rb', line 11

def y
  @y
end

Class Method Details

.touch_last_timeObject



50
51
52
# File 'lib/fusuma/swipe.rb', line 50

def touch_last_time
  @last_time = Time.now
end

Instance Method Details

#directionObject



13
14
15
16
# File 'lib/fusuma/swipe.rb', line 13

def direction
  return x > 0 ? 'right' : 'left' if x.abs > y.abs
  y > 0 ? 'down' : 'up'
end

#enough?Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/fusuma/swipe.rb', line 18

def enough?
  MultiLogger.debug(x: x, y: y)
  enough_distance? && enough_interval? && self.class.touch_last_time
end