Sha256: 65f7869137c0e2eaabe4f46e344600f5a05c1f4d5995f4933fac2b1fd198bc27

Contents?: true

Size: 812 Bytes

Versions: 7

Compression:

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

    # 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

7 entries across 7 versions & 1 rubygems

Version Path
vedeu-0.4.18 lib/vedeu/input/key.rb
vedeu-0.4.17 lib/vedeu/input/key.rb
vedeu-0.4.16 lib/vedeu/input/key.rb
vedeu-0.4.15 lib/vedeu/input/key.rb
vedeu-0.4.14 lib/vedeu/input/key.rb
vedeu-0.4.13 lib/vedeu/input/key.rb
vedeu-0.4.12 lib/vedeu/input/key.rb