lib/fusuma/plugin/buffers/gesture_buffer.rb in fusuma-1.4.1 vs lib/fusuma/plugin/buffers/gesture_buffer.rb in fusuma-1.5.0

- old
+ new

@@ -23,16 +23,25 @@ # - gesture event buffer # - window event buffer # - other event buffer return if event&.tag != source - delete_old_events - @events.push(event) clear unless updating? end + def clear_expired(current_time: Time.now) + @seconds_to_keep ||= (config_params(:seconds_to_keep) || DEFAULT_SECONDS_TO_KEEP) + @events.each do |e| + break if current_time - e.time < @seconds_to_keep + + MultiLogger.debug("#{self.class.name}##{__method__}") + + @events.delete(e) + end + end + # @param attr [Symbol] # @return [Float] def sum_attrs(attr) @events.map { |gesture_event| gesture_event.record.direction[attr].to_f } .inject(:+) @@ -67,19 +76,9 @@ events = @events.select { |event| yield event } self.class.new events end private - - # Delete old events pushed before 0.1sec - def delete_old_events - @seconds_to_keep ||= (config_params(:seconds_to_keep) || DEFAULT_SECONDS_TO_KEEP) - @events.each do |e| - break if Time.now - e.time < @seconds_to_keep - - @events.delete(e) - end - end def updating? return true unless @events.last.record.status =~ /begin|end/ end end