Sha256: b19ef0dacdd81be704f77a02a63a1c34d46280e02a198c5c9f9c49beb5b68555

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

Contents

module Vedeu

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

    class << self

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

        new(input, &block)
      end

    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

4 entries across 4 versions & 1 rubygems

Version Path
vedeu-0.3.4 lib/vedeu/input/key.rb
vedeu-0.3.3 lib/vedeu/input/key.rb
vedeu-0.3.2 lib/vedeu/input/key.rb
vedeu-0.3.1 lib/vedeu/input/key.rb