Sha256: 4a62d953e88516b744d830a8027dce9953deda4cbd64b411919084e7f9958685

Contents?: true

Size: 772 Bytes

Versions: 6

Compression:

Stored size: 772 Bytes

Contents

# frozen_string_literal: true

module Fusuma
  module Plugin
    module Buffers
      # Buffer events having KeypressRecord
      class KeypressBuffer < Buffer
        DEFAULT_SOURCE = 'keypress_parser'

        # @param event [Event]
        def buffer(event)
          return if event&.tag != source

          @events.push(event)
        end

        def clear_expired(*)
          return if @events.empty?

          return unless released?

          released_code = @events.last.record.code
          @events.delete_if { |e| e.record.code == released_code }
        end

        def empty?
          @events.empty?
        end

        private

        def released?
          true if @events.last.record.status =~ /released/
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
fusuma-plugin-keypress-0.5.0 lib/fusuma/plugin/buffers/keypress_buffer.rb
fusuma-plugin-keypress-0.4.2 lib/fusuma/plugin/buffers/keypress_buffer.rb
fusuma-plugin-keypress-0.4.1 lib/fusuma/plugin/buffers/keypress_buffer.rb
fusuma-plugin-keypress-0.4.0 lib/fusuma/plugin/buffers/keypress_buffer.rb
fusuma-plugin-keypress-0.4.0.pre2 lib/fusuma/plugin/buffers/keypress_buffer.rb
fusuma-plugin-keypress-0.4.0.pre lib/fusuma/plugin/buffers/keypress_buffer.rb