Sha256: e71d975f1582f520180d62e8d781ed738f7a73f2ad20b5121761a75a0212185d

Contents?: true

Size: 962 Bytes

Versions: 5

Compression:

Stored size: 962 Bytes

Contents

module Vedeu

  module Input

    # A single keypress or combination of keypresses bound to a
    # specific action.
    #
    class Key

      # @!attribute [r] input
      # @return [String|Symbol] Returns the key defined.
      attr_reader :input
      alias_method :key, :input

      # Returns a new instance of Vedeu::Input::Key.
      #
      # @param input [String|Symbol]
      # @param block [Proc]
      # @raise [Vedeu::Error::InvalidSyntax] The required block was
      #   not given.
      # @return [Vedeu::Input::Key]
      def initialize(input = nil, &block)
        fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?

        @input  = input
        @output = block
      end

      # Pressing the key will call the procedure.
      #
      # @return [|Symbol]
      def output
        @output.call
      end
      alias_method :action, :output
      alias_method :press, :output

    end # Key

  end # Input

end # Vedeu

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
vedeu-0.6.12 lib/vedeu/input/key.rb
vedeu-0.6.11 lib/vedeu/input/key.rb
vedeu-0.6.10 lib/vedeu/input/key.rb
vedeu-0.6.9 lib/vedeu/input/key.rb
vedeu-0.6.8 lib/vedeu/input/key.rb