Class: SqlPostgres::PgCircle

Inherits:
PgType
  • Object
show all
Defined in:
lib/sqlpostgres/PgCircle.rb

Overview

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PgType

#eql?, #hash, #to_sql

Constructor Details

#initialize(*args) ⇒ PgCircle

Constructor



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# 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

Instance Attribute Details

#centerObject (readonly)

Return the center (PgPoint)



11
12
13
# File 'lib/sqlpostgres/PgCircle.rb', line 11

def center
  @center
end

#radiusObject (readonly)

Return the radius



15
16
17
# File 'lib/sqlpostgres/PgCircle.rb', line 15

def radius
  @radius
end

Class Method Details

.from_sql(s) ⇒ Object

Create a PgCircle from a string in Postgres format



21
22
23
24
25
26
27
# 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

Instance Method Details

#to_sObject

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



51
52
53
# File 'lib/sqlpostgres/PgCircle.rb', line 51

def to_s
  "<%s, %g>" % parts
end