Class: Parse::Constraint::PolygonContainsQueryConstraint
- Inherits:
-
Parse::Constraint
- Object
- Parse::Constraint
- Parse::Constraint::PolygonContainsQueryConstraint
- Defined in:
- lib/parse/query/constraints.rb
Overview
Equivalent to the $geoIntersects Parse query operation with $point
subconstraint. This is the inverse of within_polygon: it queries a
column of type Polygon and returns objects whose stored polygon
contains the supplied GeoPoint. Matches Parse.Query#polygonContains
in the JS SDK.
q.where :area.polygon_contains => geopoint
pt = Parse::GeoPoint.new 25.7823, -80.2660 Region.all :area.polygon_contains => pt
Instance Attribute Summary
Attributes inherited from Parse::Constraint
#operand, #operation, #operator, #value
Instance Method Summary collapse
-
#build ⇒ Hash
The compiled constraint.
-
#polygon_contains ⇒ PolygonContainsQueryConstraint
A registered method on a symbol to create the constraint.
Methods inherited from Parse::Constraint
#as_json, constraint_keyword, create, formatted_value, #formatted_value, #initialize, #key, #precedence, #regex_unicode_option, register, #to_s
Constructor Details
This class inherits a constructor from Parse::Constraint
Instance Method Details
#build ⇒ Hash
Returns the compiled constraint.
2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 |
# File 'lib/parse/query/constraints.rb', line 2158 def build value = formatted_value point = case value when Parse::GeoPoint { __type: "GeoPoint", latitude: value.latitude, longitude: value.longitude } when Array unless value.length == 2 && value[0].is_a?(Numeric) && value[1].is_a?(Numeric) raise ArgumentError, "[Parse::Query] Invalid value for `polygon_contains` constraint: " \ "expected Parse::GeoPoint or [lat, lng] numeric pair." end { __type: "GeoPoint", latitude: value[0], longitude: value[1] } when Hash normalized = value.respond_to?(:symbolize_keys) ? value.symbolize_keys : value type = normalized[:__type] || normalized["__type"] lat = normalized[:latitude] || normalized[:lat] lng = normalized[:longitude] || normalized[:lng] unless type.to_s == "GeoPoint" && lat.is_a?(Numeric) && lng.is_a?(Numeric) raise ArgumentError, "[Parse::Query] Invalid value for `polygon_contains` constraint: " \ "Hash must be the GeoPoint wire shape " \ "{ __type: 'GeoPoint', latitude:, longitude: }." end { __type: "GeoPoint", latitude: lat, longitude: lng } else raise ArgumentError, "[Parse::Query] Invalid value for `polygon_contains` constraint: " \ "expected Parse::GeoPoint or [lat, lng] numeric pair." end { @operation.operand => { :$geoIntersects => { :$point => point } } } end |
#polygon_contains ⇒ PolygonContainsQueryConstraint
A registered method on a symbol to create the constraint. Maps to
Parse operator "$geoIntersects" with "$point" subconstraint. Takes a
GeoPoint (or [lat, lng] array).
2154 |
# File 'lib/parse/query/constraints.rb', line 2154 constraint_keyword :$geoIntersects |