lib/fusuma/pinch.rb in fusuma-0.9.2 vs lib/fusuma/pinch.rb in fusuma-0.10.1
- old
+ new
@@ -1,8 +1,10 @@
module Fusuma
# vector data
class Pinch
+ TYPE = 'pinch'.freeze
+
BASE_THERESHOLD = 0.3
BASE_INTERVAL = 0.05
def initialize(diameter)
@diameter = diameter.to_f
@@ -13,36 +15,37 @@
def direction
return 'in' if diameter > 0
'out'
end
- def enough?
+ def enough?(trigger)
MultiLogger.debug(diameter: diameter)
- enough_diameter? && enough_interval? && self.class.touch_last_time
+ enough_diameter?(trigger) && enough_interval?(trigger) &&
+ self.class.touch_last_time
end
private
- def enough_diameter?
- diameter.abs > threshold
+ def enough_diameter?(trigger)
+ diameter.abs > threshold(trigger)
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('pinch')
+ def threshold(trigger)
+ @threshold ||= BASE_THERESHOLD * Config.threshold(trigger)
end
- def interval_time
- @interval_time ||= BASE_INTERVAL * Config.interval('pinch')
+ def interval_time(trigger)
+ @interval_time ||= BASE_INTERVAL * Config.interval(trigger)
end
class << self
attr_reader :last_time