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, register, #to_s
Constructor Details
This class inherits a constructor from Parse::Constraint
Instance Method Details
#build ⇒ Hash
Returns the compiled constraint.
2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 |
# File 'lib/parse/query/constraints.rb', line 2134 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).
2130 |
# File 'lib/parse/query/constraints.rb', line 2130 constraint_keyword :$geoIntersects |