lib/postgis_functions/class.rb in nofxx-postgis_adapter-0.3.3 vs lib/postgis_functions/class.rb in nofxx-postgis_adapter-0.3.4

- old
+ new

@@ -1,33 +1,32 @@ module PostgisFunctions - - - ### - ## + # # Class Methods # - # Falling back to AR here. - # module ClassMethods # - # Returns the closest record - # - def closest_to(p, srid=4326) - find(:first, :order => "ST_Distance(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))" ) + # Returns the closest record + def closest_to(p, opts = {}) + srid = opts.delete(:srid) || 4326 + opts.merge!(:order => "ST_Distance(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))") + find(:first, opts) end - def close_to(p, srid=4326) - find(:all, :order => "ST_Distance(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))" ) + # + # Order by distance + def close_to(p, opts = {}) + srid = opts.delete(:srid) || 4326 + opts.merge!(:order => "ST_Distance(geom, GeomFromText('POINT(#{p.x} #{p.y})', #{srid}))") + find(:all, opts) end - # - # - # - def by_length sort='asc' - find(:all, :order => "ST_length(geom) #{sort}" ) + def by_length opts = {} + sort = opts.delete(:sort) || 'asc' + opts.merge!(:order => "ST_length(geom) #{sort}") + find(:all, opts) end def longest find(:first, :order => "ST_length(geom) DESC") end @@ -56,9 +55,9 @@ def by_boundaries sort='asc' find(:all, :order => "ST_Boundary(geom) #{sort}" ) end end - - - -end \ No newline at end of file + + + +end