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.
2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 |
# File 'lib/parse/query/constraints.rb', line 2103 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).
2099 |
# File 'lib/parse/query/constraints.rb', line 2099 constraint_keyword :$geoIntersects |