Class: SqlPostgres::PgPolygon

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

Overview

This class holds the value of a “point” column.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PgType

#eql?, #hash, #to_sql

Constructor Details

#initialize(*points) ⇒ PgPolygon

Returns a new instance of PgPolygon.



28
29
30
# File 'lib/sqlpostgres/PgPolygon.rb', line 28

def initialize(*points)
  @points = points
end

Instance Attribute Details

#pointsObject (readonly)

Returns the value of attribute points.



9
10
11
# File 'lib/sqlpostgres/PgPolygon.rb', line 9

def points
  @points
end

Class Method Details

.from_sql(s) ⇒ Object

Create a PgPolygon from a string in Postgres format



15
16
17
18
19
20
21
22
23
24
# File 'lib/sqlpostgres/PgPolygon.rb', line 15

def from_sql(s)
  if s =~ /^(\()\(.*\)(,\(.*\))?\)$/
    points = s.scan(/\([^(]*?\)/).collect do |t|
      PgPoint.from_sql(t)
    end
    PgPolygon.new(*points)
  else
    raise ArgumentError, "Invalid polygon: #{s.inspect}"
  end
end

Instance Method Details

#to_sObject



32
33
34
# File 'lib/sqlpostgres/PgPolygon.rb', line 32

def to_s
  "(#{points.join(", ")})"
end