Sha256: d4229100ec7179a1abdfc740a5115a2750651a52bf815058c8e159e1ba8023f4

Contents?: true

Size: 810 Bytes

Versions: 4

Compression:

Stored size: 810 Bytes

Contents

module Vedeu

  # Converts a position into an index for the terminal.
  #
  class PositionIndex

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

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

    alias_method :first, :y
    alias_method :last, :x

    # @param (see #initialize)
    def self.[](y, x)
      new(y, x).[]
    end

    # Returns a new instance of Vedeu::PositionIndex.
    #
    # @param y [Fixnum]
    # @param x [Fixnum]
    # @return [Vedeu::PositionIndex]
    def initialize(y, x)
      @y = ((y - 1) <= 1) ? 0 : (y - 1)
      @x = ((x - 1) <= 1) ? 0 : (x - 1)
    end

    # @return [Array]
    def []
      [y, x]
    end

    # @return [Vedeu::Position]
    def to_position
      Vedeu::Position.new(y, x)
    end

  end # PositionIndex

end # Vedeu

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vedeu-0.4.13 lib/vedeu/geometry/position_index.rb
vedeu-0.4.12 lib/vedeu/geometry/position_index.rb
vedeu-0.4.11 lib/vedeu/geometry/position_index.rb
vedeu-0.4.10 lib/vedeu/geometry/position_index.rb