Class: Parse::Constraint::PolygonContainsQueryConstraint
- Inherits:
-
Constraint
- Object
- 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 Method Summary collapse
-
#build ⇒ Hash
The compiled constraint.
-
#polygon_contains ⇒ PolygonContainsQueryConstraint
A registered method on a symbol to create the constraint.
Instance Method Details
#build ⇒ Hash
Returns the compiled constraint.
2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 |
# File 'lib/parse/query/constraints.rb', line 2886 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).
2882 |
# File 'lib/parse/query/constraints.rb', line 2882 constraint_keyword :$geoIntersects |