Sha256: 5e9f2404486e0e0cb390a62bcc8c10b028c7a29ba12119476ad5b597fcffedbd

Contents?: true

Size: 808 Bytes

Versions: 2

Compression:

Stored size: 808 Bytes

Contents

module Vedeu

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

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

      @input  = input
      @output = block
    end

    # Returns the key defined.
    #
    # @return [String|Symbol]
    def input
      @input
    end
    alias_method :key, :input

    # 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

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.4.11 lib/vedeu/input/key.rb
vedeu-0.4.10 lib/vedeu/input/key.rb