Sha256: 01cc8c8dba4a40779e31fc8be0a5fa9378b8bf4623b3956f4a54460408ec2eb7

Contents?: true

Size: 1021 Bytes

Versions: 1

Compression:

Stored size: 1021 Bytes

Contents

module Vedeu

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

    # Creates a new instance of Key.
    #
    # @see Vedeu::Key#initialize
    def self.define(input = nil, &block)
      fail InvalidSyntax, 'block not given' unless block_given?

      new(input, &block)
    end

    # 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

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.3.0 lib/vedeu/input/key.rb