Sha256: a6c1579b9f91c4d80ac93ccb91c6d69ff6f8cffb7c1b2cac2f9ac56dd903c86c

Contents?: true

Size: 1.7 KB

Versions: 12

Compression:

Stored size: 1.7 KB

Contents

module Vedeu

  # Provides the mechanism to arbitrarily move a cursor to a given position.
  #
  # @api private
  class Reposition

    # @return [Vedeu::Cursor]
    # @see Vedeu::Reposition.new
    def self.to(entity, name, y, x)
      new(entity, name, y, x).to
    end

    # Returns a new instance of Vedeu::Reposition.
    #
    # @param entity []
    # @param name [String]
    # @param y [Fixnum]
    # @param x [Fixnum]
    # @return [Vedeu::Reposition]
    def initialize(entity, name, y, x)
      @entity = entity
      @name   = name
      @y      = y
      @x      = x
    end

    # @return [Vedeu::Cursor]
    def to
      result = entity.new(name: name,
                          y:    y_position,
                          x:    x_position,
                          oy:   y,
                          ox:   x).store

      Vedeu.trigger(:_clear_, name)
      Vedeu.trigger(:_refresh_, name)
      Vedeu.trigger(:_refresh_cursor_, name)

      result
    end

    protected

    # @!attribute [r] entity
    # @return [String]
    attr_reader :entity

    # @!attribute [r] name
    # @return [String]
    attr_reader :name

    # @!attribute [r] x
    # @return [Fixnum]
    attr_reader :x

    # @!attribute [r] y
    # @return [Fixnum]
    attr_reader :y

    private

    # @return [Coordinate]
    def coordinate
      @coordinate ||= Vedeu::Coordinate.new(name)
    end

    # Returns the cursors x position based on the desired x position.
    #
    # @return [Fixnum]
    def x_position
      coordinate.x_position(x)
    end

    # Returns the cursors y position based on the desired y position.
    #
    # @return [Fixnum]
    def y_position
      coordinate.y_position(y)
    end

  end # Reposition

end # Vedeu

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
vedeu-0.4.55 lib/vedeu/cursor/reposition.rb
vedeu-0.4.54 lib/vedeu/cursor/reposition.rb
vedeu-0.4.53 lib/vedeu/cursor/reposition.rb
vedeu-0.4.52 lib/vedeu/cursor/reposition.rb
vedeu-0.4.51 lib/vedeu/cursor/reposition.rb
vedeu-0.4.50 lib/vedeu/cursor/reposition.rb
vedeu-0.4.49 lib/vedeu/cursor/reposition.rb
vedeu-0.4.48 lib/vedeu/cursor/reposition.rb
vedeu-0.4.47 lib/vedeu/cursor/reposition.rb
vedeu-0.4.46 lib/vedeu/cursor/reposition.rb
vedeu-0.4.45 lib/vedeu/cursor/reposition.rb
vedeu-0.4.44 lib/vedeu/cursor/reposition.rb