Class: SqlPostgres::PgTwoPoints

Inherits:
PgType
  • Object
show all
Defined in:
lib/sqlpostgres/PgTwoPoints.rb

Overview

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

Direct Known Subclasses

PgBox, PgLineSegment

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from PgType

#eql?, #hash, #to_sql

Constructor Details

#initialize(*args) ⇒ PgTwoPoints

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



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/sqlpostgres/PgTwoPoints.rb', line 20

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

Instance Attribute Details

#p1Object (readonly)

Return the first endpoint



11
12
13
# File 'lib/sqlpostgres/PgTwoPoints.rb', line 11

def p1
  @p1
end

#p2Object (readonly)

Return the second endpoint



15
16
17
# File 'lib/sqlpostgres/PgTwoPoints.rb', line 15

def p2
  @p2
end

Instance Method Details

#to_sObject

Return a string representation (ie “((1, 2), (3, 4))”).



36
37
38
# File 'lib/sqlpostgres/PgTwoPoints.rb', line 36

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