Class: Fusuma::Plugin::Detectors::SwipeDetector::Direction

Inherits:
Object
  • Object
show all
Defined in:
lib/fusuma/plugin/detectors/swipe_detector.rb

Overview

direction of gesture

Constant Summary collapse

RIGHT =
'right'
LEFT =
'left'
DOWN =
'down'
UP =
'up'

Instance Method Summary collapse

Constructor Details

#initialize(move_x:, move_y:) ⇒ Direction

Returns a new instance of Direction.



105
106
107
108
# File 'lib/fusuma/plugin/detectors/swipe_detector.rb', line 105

def initialize(move_x:, move_y:)
  @move_x = move_x
  @move_y = move_y
end

Instance Method Details

#calcObject



114
115
116
117
118
119
120
121
122
# File 'lib/fusuma/plugin/detectors/swipe_detector.rb', line 114

def calc
  if @move_x.abs > @move_y.abs
    @move_x > 0 ? RIGHT : LEFT
  elsif @move_y > 0
    DOWN
  else
    UP
  end
end

#to_sObject



110
111
112
# File 'lib/fusuma/plugin/detectors/swipe_detector.rb', line 110

def to_s
  calc
end