Sha256: f18e5b0531a1260da3a30c0fcaa2b5d5debd103031e345095b52293d2134805c

Contents?: true

Size: 826 Bytes

Versions: 22

Compression:

Stored size: 826 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 [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

22 entries across 22 versions & 1 rubygems

Version Path
vedeu-0.4.58 lib/vedeu/input/key.rb
vedeu-0.4.57 lib/vedeu/input/key.rb