Sha256: 901ec0f26dcef50a8525dfc5012a838d4665bcc1412e0dcb22738f5ca9618d46

Contents?: true

Size: 891 Bytes

Versions: 3

Compression:

Stored size: 891 Bytes

Contents

# frozen_string_literal: true

module Vedeu

  module Input

    # 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 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

3 entries across 3 versions & 1 rubygems

Version Path
vedeu-0.8.23 lib/vedeu/input/key.rb
vedeu-0.8.22 lib/vedeu/input/key.rb
vedeu-0.8.21 lib/vedeu/input/key.rb