Sha256: 626e44dd4211c0a59e0e6121a4cd9695582e80b4bfca5fb73f3c3d870a80d005

Contents?: true

Size: 1.1 KB

Versions: 1

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module Fusuma
  module Plugin
    module Detectors
      # Detect KeypressEvent from KeypressBuffer
      class AppmatcherDetector < Detector
        BUFFER_TYPE = 'appmatcher'

        DEFAULT_NAME = 'global'

        # @param buffers [Array<Event>]
        # @return [Event] if event is detected
        # @return [NilClass] if event is NOT detected
        def detect(buffers)
          buffer = buffers.find { |b| b.type == BUFFER_TYPE }

          return if buffer.empty?

          record = buffer.events.last.record

          index_record = Events::Records::IndexRecord.new(
            index: create_index(record: record),
            position: :prefix
          )

          create_event(record: index_record)
        end

        # @param record [Events::Records::KeypressRecord]
        # @return [Config::Index]
        def create_index(record:)
          Config::Index.new(
            [
              Config::Index::Key.new('application'),
              Config::Index::Key.new(record.name, fallback: DEFAULT_NAME)
            ]
          )
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fusuma-plugin-appmatcher-0.1.0.pre lib/fusuma/plugin/detectors/appmatcher_detector.rb