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.5.12 lib/vedeu/input/key.rb
vedeu-0.5.11 lib/vedeu/input/key.rb
vedeu-0.5.10 lib/vedeu/input/key.rb
vedeu-0.5.9 lib/vedeu/input/key.rb
vedeu-0.5.8 lib/vedeu/input/key.rb
vedeu-0.5.7 lib/vedeu/input/key.rb
vedeu-0.5.6 lib/vedeu/input/key.rb
vedeu-0.5.5 lib/vedeu/input/key.rb
vedeu-0.5.4 lib/vedeu/input/key.rb
vedeu-0.5.3 lib/vedeu/input/key.rb
vedeu-0.5.2 lib/vedeu/input/key.rb
vedeu-0.5.1 lib/vedeu/input/key.rb
vedeu-0.5.0 lib/vedeu/input/key.rb
vedeu-0.4.65 lib/vedeu/input/key.rb
vedeu-0.4.64 lib/vedeu/input/key.rb
vedeu-0.4.63 lib/vedeu/input/key.rb
vedeu-0.4.62 lib/vedeu/input/key.rb
vedeu-0.4.61 lib/vedeu/input/key.rb
vedeu-0.4.60 lib/vedeu/input/key.rb
vedeu-0.4.59 lib/vedeu/input/key.rb