Sha256: 7dccc4b56073be968945028cdde156b82a8a44fc9b8506cf782bcced3eb029f1

Contents?: true

Size: 801 Bytes

Versions: 8

Compression:

Stored size: 801 Bytes

Contents

module Vedeu

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

    # Returns a new instance of 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

8 entries across 8 versions & 1 rubygems

Version Path
vedeu-0.4.9 lib/vedeu/input/key.rb
vedeu-0.4.8 lib/vedeu/input/key.rb
vedeu-0.4.7 lib/vedeu/input/key.rb
vedeu-0.4.6 lib/vedeu/input/key.rb
vedeu-0.4.5 lib/vedeu/input/key.rb
vedeu-0.4.4 lib/vedeu/input/key.rb
vedeu-0.4.3 lib/vedeu/input/key.rb
vedeu-0.4.2 lib/vedeu/input/key.rb