Sha256: f583c244254f7fc6d61e69330471124441f6eb0d3da50f31eef557d99ae91e33

Contents?: true

Size: 1.32 KB

Versions: 15

Compression:

Stored size: 1.32 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[-1]
      end

      # @return [NilClass|Symbol|String]
      def last_keypress
        all_keypresses[-1]
      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

15 entries across 15 versions & 1 rubygems

Version Path
vedeu-0.6.39 lib/vedeu/input/store.rb
vedeu-0.6.38 lib/vedeu/input/store.rb
vedeu-0.6.37 lib/vedeu/input/store.rb
vedeu-0.6.36 lib/vedeu/input/store.rb
vedeu-0.6.35 lib/vedeu/input/store.rb
vedeu-0.6.34 lib/vedeu/input/store.rb
vedeu-0.6.33 lib/vedeu/input/store.rb
vedeu-0.6.32 lib/vedeu/input/store.rb
vedeu-0.6.31 lib/vedeu/input/store.rb
vedeu-0.6.30 lib/vedeu/input/store.rb
vedeu-0.6.29 lib/vedeu/input/store.rb
vedeu-0.6.28 lib/vedeu/input/store.rb
vedeu-0.6.27 lib/vedeu/input/store.rb
vedeu-0.6.26 lib/vedeu/input/store.rb
vedeu-0.6.25 lib/vedeu/input/store.rb