Class: SqlPostgres::PgPath
Overview
This class holds the value of a “path” column.
Instance Attribute Summary collapse
-
#closed ⇒ Object
readonly
Returns the value of attribute closed.
-
#points ⇒ Object
readonly
Returns the value of attribute points.
Class Method Summary collapse
-
.from_sql(s) ⇒ Object
Create a PgPath from a string in Postgres format.
Instance Method Summary collapse
-
#initialize(closed = true, *points) ⇒ PgPath
constructor
A new instance of PgPath.
- #to_s ⇒ Object
Methods inherited from PgType
Constructor Details
#initialize(closed = true, *points) ⇒ PgPath
Returns a new instance of PgPath.
30 31 32 33 |
# File 'lib/sqlpostgres/PgPath.rb', line 30 def initialize(closed = true, *points) @points = points @closed = closed end |
Instance Attribute Details
#closed ⇒ Object (readonly)
Returns the value of attribute closed.
10 11 12 |
# File 'lib/sqlpostgres/PgPath.rb', line 10 def closed @closed end |
#points ⇒ Object (readonly)
Returns the value of attribute points.
9 10 11 |
# File 'lib/sqlpostgres/PgPath.rb', line 9 def points @points end |
Class Method Details
.from_sql(s) ⇒ Object
Create a PgPath from a string in Postgres format
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sqlpostgres/PgPath.rb', line 16 def from_sql(s) if s =~ /^(\[)\(.*\)(,\(.*\))?\]$/ || s =~ /^(\()\(.*\)(,\(.*\))?\)$/ closed = $1 == "(" points = s.scan(/\([^(]*?\)/).collect do |t| PgPoint.from_sql(t) end PgPath.new(closed, *points) else raise ArgumentError, "Invalid path: #{s.inspect}" end end |
Instance Method Details
#to_s ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/sqlpostgres/PgPath.rb', line 35 def to_s s = points.join(", ") if closed "(#{s})" else "[#{s}]" end end |