Sha256: ac44777529aabfdf8e0d0b5fae43a084ec1686d5e679d0643674c9ac60ebb33b

Contents?: true

Size: 916 Bytes

Versions: 9

Compression:

Stored size: 916 Bytes

Contents

# frozen_string_literal: true

module Vedeu

  module Input

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

      # @!attribute [r] input
      # @return [String|Symbol] Returns the key defined.
      attr_reader :input
      alias key input

      # Returns a new instance of Vedeu::Input::Key.
      #
      # @param input [String|Symbol]
      # @macro param_block
      # @macro raise_requires_block
      # @return [Vedeu::Input::Key]
      def initialize(input = nil, &block)
        raise Vedeu::Error::RequiresBlock unless block_given?

        @input  = input
        @output = block
      end

      # Pressing the key will call the procedure.
      #
      # @return [|Symbol]
      def output
        @output.call
      end
      alias action output
      alias press output

    end # Key

  end # Input

end # Vedeu

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
vedeu-0.8.32 lib/vedeu/input/key.rb
vedeu-0.8.31 lib/vedeu/input/key.rb
vedeu-0.8.30 lib/vedeu/input/key.rb
vedeu-0.8.29 lib/vedeu/input/key.rb
vedeu-0.8.28 lib/vedeu/input/key.rb
vedeu-0.8.27 lib/vedeu/input/key.rb
vedeu-0.8.26 lib/vedeu/input/key.rb
vedeu-0.8.25 lib/vedeu/input/key.rb
vedeu-0.8.24 lib/vedeu/input/key.rb