class SqlPostgres::PgPolygon

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

Attributes

points[R]

Public Class Methods

from_sql(s) click to toggle source

Create a PgPolygon from a string in Postgres format

# 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
new(*points) click to toggle source
# File lib/sqlpostgres/PgPolygon.rb, line 28
def initialize(*points)
  @points = points
end

Public Instance Methods

to_s() click to toggle source
# File lib/sqlpostgres/PgPolygon.rb, line 32
def to_s
  "(#{points.join(", ")})"
end

Protected Instance Methods

parts() click to toggle source
# File lib/sqlpostgres/PgPolygon.rb, line 38
def parts
  points
end

Private Instance Methods

column_type() click to toggle source
# File lib/sqlpostgres/PgPolygon.rb, line 44
def column_type
  'polygon'
end