Sha256: e8f579fd12b4b448f341e1ccf846c81f3c24981d6d506188992275ab5bf37e9f

Contents?: true

Size: 1.33 KB

Versions: 7

Compression:

Stored size: 1.33 KB

Contents

module Vedeu

  module Input

    # Stores each keypress or command to be retrieved later.
    #
    class Store

      def initialize
      end

      # @return [Hash<Symbol => Array<Symbol|String>>]
      def add_command(command)
        all_commands << command
      end

      # @return [Hash<Symbol => Array<Symbol|String>>]
      def add_keypress(keypress)
        all_keypresses << keypress
      end

      # @return [Hash<Symbol => Array<Symbol|String>>]
      def all
        storage
      end

      # @return [Array<Symbol|String>]
      def all_commands
        storage[:commands]
      end

      # @return [Array<Symbol|String>]
      def all_keypresses
        storage[:keypresses]
      end

      # @return [NilClass|Symbol|String]
      def last_command
        all_commands.last
      end

      # @return [NilClass|Symbol|String]
      def last_keypress
        all_keypresses.last
      end

      # @return [Hash<Symbol => Array<Symbol|String>>]
      def reset
        @storage = in_memory
      end

      private

      # @return [Hash<Symbol => Array<Symbol|String>>]
      def storage
        @storage ||= in_memory
      end

      # @return [Hash<Symbol => Array<Symbol|String>>]
      def in_memory
        {
          commands:   [],
          keypresses: [],
        }
      end

    end # Store

  end # Input

end # Vedeu

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
vedeu-0.6.24 lib/vedeu/input/store.rb
vedeu-0.6.23 lib/vedeu/input/store.rb
vedeu-0.6.22 lib/vedeu/input/store.rb
vedeu-0.6.21 lib/vedeu/input/store.rb
vedeu-0.6.20 lib/vedeu/input/store.rb
vedeu-0.6.19 lib/vedeu/input/store.rb
vedeu-0.6.18 lib/vedeu/input/store.rb