Sha256: ea189aadd198550e3e6897a4812407f334083121a5fc100363eec1a956e36c08

Contents?: true

Size: 935 Bytes

Versions: 3

Compression:

Stored size: 935 Bytes

Contents

require 'sqlpostgres/PgType'

module SqlPostgres

  # This is the base class for data types which have two points

  class PgTwoPoints < PgType

    # Return the first endpoint

    attr_reader :p1

    # Return the second endpoint

    attr_reader :p2

    # Constructor.  Takes either 0 arguments, which sets both endpoints
    # to (0, 0), or 2 PgPoint arguments, or 4 float arguments.

    def initialize(*args)
      case args.size
      when 0
        @p1 = PgPoint.new
        @p2 = PgPoint.new
      when 2
        @p1 = args[0]
        @p2 = args[1]
      when 4
        @p1 = PgPoint.new(*args[0..1])
        @p2 = PgPoint.new(*args[2..3])
      end
    end

    # Return a string representation (ie "((1, 2), (3, 4))").

    def to_s
      "(%s, %s)" % [p1, p2]
    end

    protected

    def parts
      [p1, p2]
    end

  end

end

# Local Variables:
# tab-width: 2
# ruby-indent-level: 2
# indent-tabs-mode: nil
# End:

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sqlpostgres-1.2.6 lib/sqlpostgres/PgTwoPoints.rb
sqlpostgres-1.2.5 lib/sqlpostgres/PgTwoPoints.rb
sqlpostgres-1.2.4 lib/sqlpostgres/PgTwoPoints.rb