class SqlPostgres::PgPoint
This class holds the value of a “point” column.
Attributes
x[R]
Return the x coordinate
y[R]
Return the y coordinate
Public Class Methods
from_sql(s)
click to toggle source
Create a PgPoint
from a string in Postgres format (ie “(1,2)”).
# File lib/sqlpostgres/PgPoint.rb, line 22 def from_sql(s) if s =~ /^\((.*?),(.*\))$/ PgPoint.new($1.to_f, $2.to_f) else raise ArgumentError, "Invalid point: #{s.inspect}" end end
new(x = 0, y = 0)
click to toggle source
Constructor taking the x and y coordinate
# File lib/sqlpostgres/PgPoint.rb, line 34 def initialize(x = 0, y = 0) @x = x @y = y end
Public Instance Methods
to_s()
click to toggle source
Return a string representation (ie “(1, 2)”).
# File lib/sqlpostgres/PgPoint.rb, line 41 def to_s "(%g, %g)" % parts end
Protected Instance Methods
parts()
click to toggle source
# File lib/sqlpostgres/PgPoint.rb, line 47 def parts [x, y] end
Private Instance Methods
column_type()
click to toggle source
# File lib/sqlpostgres/PgPoint.rb, line 53 def column_type 'point' end