Sha256: 109e40f09ac5af4306b111c18eea4a65abf1676f904960bd4c18f373f107df40

Contents?: true

Size: 892 Bytes

Versions: 8

Compression:

Stored size: 892 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]
      # @param block [Proc]
      # @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

8 entries across 8 versions & 1 rubygems

Version Path
vedeu-0.8.20 lib/vedeu/input/key.rb
vedeu-0.8.19 lib/vedeu/input/key.rb
vedeu-0.8.18 lib/vedeu/input/key.rb
vedeu-0.8.17 lib/vedeu/input/key.rb
vedeu-0.8.16 lib/vedeu/input/key.rb
vedeu-0.8.15 lib/vedeu/input/key.rb
vedeu-0.8.14 lib/vedeu/input/key.rb
vedeu-0.8.13 lib/vedeu/input/key.rb