Class: Fusuma::Plugin::Buffers::Buffer

Inherits:
Fusuma::Plugin::Base show all
Defined in:
lib/fusuma/plugin/buffers/buffer.rb

Overview

buffer events and output

Direct Known Subclasses

GestureBuffer, TimerBuffer

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Fusuma::Plugin::Base

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

Constructor Details

#initialize(*args) ⇒ Buffer

Returns a new instance of Buffer.



10
11
12
13
# File 'lib/fusuma/plugin/buffers/buffer.rb', line 10

def initialize(*args)
  super()
  @events = Array.new(*args)
end

Instance Attribute Details

#eventsObject (readonly)

Returns the value of attribute events.



15
16
17
# File 'lib/fusuma/plugin/buffers/buffer.rb', line 15

def events
  @events
end

Instance Method Details

#buffer(event) ⇒ Object

Parameters:

  • event (Event)


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

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

  @events.push(event)
end

#clearObject

clear buffer



40
41
42
# File 'lib/fusuma/plugin/buffers/buffer.rb', line 40

def clear
  @events.clear
end

#clear_expired(current_time: Time.now) ⇒ Object

clear old events

Parameters:

  • current_time (Time) (defaults to: Time.now)


31
32
# File 'lib/fusuma/plugin/buffers/buffer.rb', line 31

def clear_expired(current_time: Time.now)
end

#empty?TrueClass, FalseClass

Returns:

  • (TrueClass, FalseClass)


35
36
37
# File 'lib/fusuma/plugin/buffers/buffer.rb', line 35

def empty?
  @events.empty?
end

#sourceObject

Set source for tag from config.yml. DEFAULT_SOURCE is defined in each plugins.



46
47
48
# File 'lib/fusuma/plugin/buffers/buffer.rb', line 46

def source
  @source ||= config_params(:source) || self.class.const_get(:DEFAULT_SOURCE)
end

#typeString

Returns:



18
19
20
# File 'lib/fusuma/plugin/buffers/buffer.rb', line 18

def type
  @type ||= self.class.name.underscore.split("/").last.gsub("_buffer", "")
end