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.



138
139
140
141
# File 'lib/fusuma/plugin/detectors/swipe_detector.rb', line 138

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

Instance Method Details

#calcObject



147
148
149
150
151
152
153
154
155
# File 'lib/fusuma/plugin/detectors/swipe_detector.rb', line 147

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

#to_sObject



143
144
145
# File 'lib/fusuma/plugin/detectors/swipe_detector.rb', line 143

def to_s
  calc
end