lib/fusuma/swipe.rb in fusuma-0.9.2 vs lib/fusuma/swipe.rb in fusuma-0.10.1

- old
+ new

@@ -1,48 +1,52 @@ module Fusuma # vector data class Swipe + TYPE = 'swipe'.freeze + BASE_THERESHOLD = 20 BASE_INTERVAL = 0.5 - def initialize(x, y) - @x = x - @y = y + def initialize(move_x, move_y) + @x = move_x + @y = move_y end attr_reader :x, :y def direction return x > 0 ? 'right' : 'left' if x.abs > y.abs y > 0 ? 'down' : 'up' end - def enough? + def enough?(trigger) MultiLogger.debug(x: x, y: y) - enough_distance? && enough_interval? && self.class.touch_last_time + enough_distance?(trigger) && enough_interval?(trigger) && + self.class.touch_last_time end private - def enough_distance? + def enough_distance?(trigger) + threshold = threshold(trigger) (x.abs > threshold) || (y.abs > threshold) end - def enough_interval? + def enough_interval?(trigger) return true if first_time? - return true if (Time.now - self.class.last_time) > interval_time + return true if (Time.now - self.class.last_time) > interval_time(trigger) false end def first_time? - self.class.last_time.nil? + !self.class.last_time end - def threshold - @threshold ||= BASE_THERESHOLD * Config.threshold('swipe') + def threshold(trigger) + @threshold ||= BASE_THERESHOLD * Config.threshold(trigger) end - def interval_time - @interval_time ||= BASE_INTERVAL * Config.interval('swipe') + def interval_time(trigger) + @interval_time ||= BASE_INTERVAL * Config.interval(trigger) end class << self attr_reader :last_time