Sha256: 7c8f064b1e9cca2e8933d40a56b4a7dbd69ba6bd2f97088ecfe92e3e89ffa9d5

Contents?: true

Size: 833 Bytes

Versions: 3

Compression:

Stored size: 833 Bytes

Contents

module Vedeu

  # 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::Key.
    #
    # @param input [String|Symbol]
    # @param block [Proc]
    # @raise [Vedeu::InvalidSyntax] The required block was not given.
    # @return [Vedeu::Key]
    def initialize(input = nil, &block)
      fail Vedeu::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 # Vedeu

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
vedeu-0.6.1 lib/vedeu/input/key.rb
vedeu-0.6.0 lib/vedeu/input/key.rb
vedeu-0.5.13 lib/vedeu/input/key.rb