class NoBrainer::GeoSpatial::Point
Public Class Methods
nobrainer_cast_db_to_model(value)
click to toggle source
This class method translates a value from the database to the proper type. It is used when reading from the database.
# File lib/nobrainer_geospatial/types/geo_point.rb, line 31 def nobrainer_cast_db_to_model(value) NoBrainer::GeoSpatial::Point.new(value['coordinates'][0], value['coordinates'][1]) end
nobrainer_cast_model_to_db(value)
click to toggle source
# File lib/nobrainer_geospatial/types/geo_point.rb, line 25 def nobrainer_cast_model_to_db(value) RethinkDB::RQL.new.point(value.longitude, value.latitude) end
nobrainer_cast_user_to_model(value)
click to toggle source
# File lib/nobrainer_geospatial/types/geo_point.rb, line 9 def nobrainer_cast_user_to_model(value) case value when NoBrainer::GeoSpatial::Point then value when Array then new(value[0], value[1]) when Hash then longitude = value[:longitude] ||= value[:long] ||= value['longitude'] ||= value['long'] latitude = value[:latitude] ||= value[:lat] ||= value['latitude'] ||= value['latitude'] raise NoBrainer::Error::InvalidType.new('longitude out of range') if longitude < -180 || longitude > 180 raise NoBrainer::Error::InvalidType.new('latitude out of range') if latitude < -90 || latitude > 90 raise 'You must supply :longitude and :latitude!' unless latitude && longitude new(longitude, latitude) else raise NoBrainer::Error::InvalidType end end
Public Instance Methods
to_rql()
click to toggle source
# File lib/nobrainer_geospatial/types/geo_point.rb, line 4 def to_rql RethinkDB::RQL.new.point(self.longitude, self.latitude) end