Sha256: 88d13173d93a0bf6416aecdff041e77f74a02fdc1458033beeb0dc19b95df6cc

Contents?: true

Size: 789 Bytes

Versions: 2

Compression:

Stored size: 789 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 y [Fixnum]
    # @param x [Fixnum]
    # @return [Array]
    def self.[](y, x)
      new(y, x).[]
    end

    # @param y [Fixnum]
    # @param x [Fixnum]
    # @return [Vedeu::PositionIndex]
    def initialize(y, x)
      @y = ((y - 1) <= 1) ? 1 : (y - 1)
      @x = ((x - 1) <= 1) ? 1 : (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

2 entries across 2 versions & 1 rubygems

Version Path
vedeu-0.4.7 lib/vedeu/geometry/position_index.rb
vedeu-0.4.6 lib/vedeu/geometry/position_index.rb