Sha256: 98f6dbaa186b4800620fb25f87defe485b99e5b941ce483bc2dc98f9c01504cd

Contents?: true

Size: 847 Bytes

Versions: 6

Compression:

Stored size: 847 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::Error::InvalidSyntax] The required block was not given.
    # @return [Vedeu::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 # Vedeu

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vedeu-0.6.7 lib/vedeu/input/key.rb
vedeu-0.6.6 lib/vedeu/input/key.rb
vedeu-0.6.5 lib/vedeu/input/key.rb
vedeu-0.6.4 lib/vedeu/input/key.rb
vedeu-0.6.3 lib/vedeu/input/key.rb
vedeu-0.6.2 lib/vedeu/input/key.rb