Sha256: be1b0dab596864303e159647a32b01ce35a8e7ead8d00b749947ff355217b75b

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

module Vedeu

  module Cursors

    # @api private
    #
    class Move

      extend Forwardable

      def_delegators :cursor,
                     :visible?

      # @param name [String|Symbol]
      # @param direction [Symbol]
      # @return [Vedeu::Cursors::Cursor]
      def self.move(name, direction)
        new(name, direction).move
      end

      # @param name [String|Symbol]
      # @param direction [Symbol]
      # @return [Vedeu::Cursors::Move]
      def initialize(name, direction)
        @name      = name
        @direction = direction
      end

      # @return [NilClass|Vedeu::Cursors::Cursor]
      def move
        return nil unless visible? && valid_direction?

        cursor.public_send(direction)
        cursor.store { Vedeu.trigger(:_refresh_cursor_, name) }
        cursor
      end

      protected

      # @!attribute [r] name
      # @return [String|Symbol] The name of the cursor.
      attr_reader :name

      # @!attribute [r] direction
      # @return [Symbol] The direction to move the cursor.
      attr_reader :direction

      private

      # @return [Vedeu::Cursors::Cursor]
      def cursor
        @_cursor ||= Vedeu.cursors.by_name(name)
      end

      # @return [Boolean]
      def valid_direction?
        [
          :move_down,
          :move_left,
          :move_right,
          :move_up,
        ].include?(direction)
      end

    end # Move

  end # Cursors

end # Vedeu

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.6.70 lib/vedeu/cursors/move.rb