Sha256: 58ae15dc8376e22ef95bcec0c757e31f9d01c2af983e96fa786fcec23a484335

Contents?: true

Size: 1020 Bytes

Versions: 18

Compression:

Stored size: 1020 Bytes

Contents

module Fusuma
  # vector data
  class Pinch
    BASE_THERESHOLD = 0.3
    BASE_INTERVAL   = 0.05

    def initialize(diameter)
      @diameter = diameter.to_f
    end

    attr_reader :diameter

    def direction
      return 'in' if diameter > 0
      'out'
    end

    def enough?
      MultiLogger.debug(diameter: diameter)
      enough_diameter? && enough_interval? && self.class.touch_last_time
    end

    private

    def enough_diameter?
      diameter.abs > threshold
    end

    def enough_interval?
      return true if first_time?
      return true if (Time.now - self.class.last_time) > interval_time
      false
    end

    def first_time?
      self.class.last_time.nil?
    end

    def threshold
      @threshold ||= BASE_THERESHOLD * Config.threshold('pinch')
    end

    def interval_time
      @interval_time ||= BASE_INTERVAL * Config.interval('pinch')
    end

    class << self
      attr_reader :last_time

      def touch_last_time
        @last_time = Time.now
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
fusuma-0.9.2 lib/fusuma/pinch.rb
fusuma-0.9.1 lib/fusuma/pinch.rb
fusuma-0.9.0 lib/fusuma/pinch.rb
fusuma-0.8.0 lib/fusuma/pinch.rb
fusuma-0.7.2 lib/fusuma/pinch.rb
fusuma-0.7.1 lib/fusuma/pinch.rb
fusuma-0.7.0 lib/fusuma/pinch.rb
fusuma-0.6.0 lib/fusuma/pinch.rb
fusuma-0.5.0 lib/fusuma/pinch.rb
fusuma-0.4.1 lib/fusuma/pinch.rb
fusuma-0.4.0 lib/fusuma/pinch.rb
fusuma-0.3.7 lib/fusuma/pinch.rb
fusuma-0.3.5 lib/fusuma/pinch.rb
fusuma-0.3.4 lib/fusuma/pinch.rb
fusuma-0.3.3 lib/fusuma/pinch.rb
fusuma-0.3.2 lib/fusuma/pinch.rb
fusuma-0.3.1 lib/fusuma/pinch.rb
fusuma-0.3.0 lib/fusuma/pinch.rb