Sha256: ac6603b9431239d001632adb1dd94f5e43cc6014f223c62accada054761eb7a1

Contents?: true

Size: 1.83 KB

Versions: 1

Compression:

Stored size: 1.83 KB

Contents

module Vedeu

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

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

    # @return [Vedeu::Cursor]
    def entity
      @_entity ||= @entity.new
    end

    # @return [Vedeu::Cursor]
    def model
      @model ||= repository.by_name(name)
    end

    # @return [Vedeu::Cursors]
    def repository
      entity.repository
    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

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.4.38 lib/vedeu/cursor/reposition.rb