Class: Fusuma::Plugin::Buffers::TimerBuffer

Inherits:
Buffer show all
Defined in:
lib/fusuma/plugin/buffers/timer_buffer.rb

Overview

manage events and generate command

Constant Summary collapse

DEFAULT_SOURCE =
"timer_input"
DEFAULT_SECONDS_TO_KEEP =
3

Instance Attribute Summary

Attributes inherited from Buffer

#events

Instance Method Summary collapse

Methods inherited from Buffer

#clear, #empty?, #initialize, #source, #type

Methods inherited from Fusuma::Plugin::Base

#config_index, #config_params, inherited, plugins, #shutdown

Constructor Details

This class inherits a constructor from Fusuma::Plugin::Buffers::Buffer

Instance Method Details

#buffer(event) ⇒ Buffer, NilClass

Parameters:

  • event (Event)

Returns:



22
23
24
25
26
27
# File 'lib/fusuma/plugin/buffers/timer_buffer.rb', line 22

def buffer(event)
  return if event&.tag != source

  @events.push(event)
  self
end

#clear_expired(current_time: Time.now) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/fusuma/plugin/buffers/timer_buffer.rb', line 29

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

    @events.delete(e)
  end
end

#config_param_typesObject



13
14
15
16
17
18
# File 'lib/fusuma/plugin/buffers/timer_buffer.rb', line 13

def config_param_types
  {
    source: [String],
    seconds_to_keep: [Float, Integer]
  }
end