class Fusuma::Plugin::Detectors::KeypressDetector
Detect KeypressEvent from KeypressBuffer
Constants
- BUFFER_TYPE
- SOURCES
Public Instance Methods
create_index(records:)
click to toggle source
@param records [Array<Events::Records::KeypressRecord>] @return [Config::Index]
# File lib/fusuma/plugin/detectors/keypress_detector.rb, line 36 def create_index(records:) code = records.map(&:code).join('+') Config::Index.new( [ Config::Index::Key.new('keypress', skippable: true), Config::Index::Key.new(code, skippable: true) ] ) end
detect(buffers)
click to toggle source
@param buffers [Array<Event>] @return [Event] if event is detected @return [NilClass] if event is NOT detected
# File lib/fusuma/plugin/detectors/keypress_detector.rb, line 19 def detect(buffers) buffer = buffers.find { |b| b.type == BUFFER_TYPE } return if buffer.empty? records = buffer.events.select { |e| e.record.status == 'pressed' }.map(&:record) index_record = Events::Records::IndexRecord.new( index: create_index(records: records), position: :surfix ) create_event(record: index_record) end
watch?()
click to toggle source
Always watch buffers and detect them.
# File lib/fusuma/plugin/detectors/keypress_detector.rb, line 12 def watch? true end