class SqlPostgres::PgCircle

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

Attributes

center[R]

Return the center (PgPoint)

radius[R]

Return the radius

Public Class Methods

from_sql(s) click to toggle source

Create a PgCircle from a string in Postgres format

# File lib/sqlpostgres/PgCircle.rb, line 21
def from_sql(s)
  if s =~ /^<(.*),(.*)>$/
    PgCircle.new(PgPoint.from_sql($1), $2.to_f)
  else
    raise ArgumentError, "Invalid circle: #{s.inspect}"
  end
end
new(*args) click to toggle source

Constructor

# File lib/sqlpostgres/PgCircle.rb, line 33
def initialize(*args)
  case args.size
  when 0
    @center = PgPoint.new
    @radius = 0
  when 2
    @center = args[0]
    @radius = args[1]
  when 3
    @center = PgPoint.new(*args[0..1])
    @radius = args[2]
  else
    raise ArgumentError, "Incorrect number of arguments: #{args.size}"
  end
end

Public Instance Methods

to_s() click to toggle source

Return a string representation (ie “<(1, 2), 3>”).

# File lib/sqlpostgres/PgCircle.rb, line 51
def to_s
  "<%s, %g>" % parts
end

Protected Instance Methods

parts() click to toggle source
# File lib/sqlpostgres/PgCircle.rb, line 57
def parts
  [center, radius]
end

Private Instance Methods

column_type() click to toggle source
# File lib/sqlpostgres/PgCircle.rb, line 63
def column_type
  'circle'
end