Class: SqlPostgres::PgPolygon
- Defined in:
- lib/sqlpostgres/PgPolygon.rb
Overview
This class holds the value of a “point” column.
Instance Attribute Summary collapse
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Class Method Summary collapse
-
.from_sql(s) ⇒ Object
Create a PgPolygon from a string in Postgres format.
Instance Method Summary collapse
-
#initialize(*points) ⇒ PgPolygon
constructor
A new instance of PgPolygon.
- #to_s ⇒ Object
Methods inherited from PgType
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
#points ⇒ Object (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_s ⇒ Object
32 33 34 |
# File 'lib/sqlpostgres/PgPolygon.rb', line 32 def to_s "(#{points.join(", ")})" end |