Class: Parse::Constraint::WithinGeoBoxQueryConstraint

Inherits:
Parse::Constraint show all
Defined in:
lib/parse/query/constraints.rb

Overview

Equivalent to the `$within` Parse query operation and `$box` geopoint constraint. The rectangular bounding box is defined by a southwest point as the first parameter, followed by the a northeast point. Please note that Geo box queries that cross the international date lines are not currently supported by Parse.

q.where :field.within_box => [soutwestGeoPoint, northeastGeoPoint]

sw = Parse::GeoPoint.new 32.82, -117.23 # San Diego
ne = Parse::GeoPoint.new 36.12, -115.31 # Las Vegas

# get all PlaceObjects inside this bounding box
PlaceObject.all :location.within_box => [sw,ne]

Instance Attribute Summary

Attributes inherited from Parse::Constraint

#operand, #operation, #operator, #value

Instance Method Summary collapse

Methods inherited from Parse::Constraint

#as_json, contraint_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

#buildHash

Returns the compiled constraint.

Returns:

  • (Hash)

    the compiled constraint.



655
656
657
658
659
660
661
662
663
664
# File 'lib/parse/query/constraints.rb', line 655

def build
  geopoint_values = formatted_value
  unless geopoint_values.is_a?(Array) && geopoint_values.count == 2 &&
         geopoint_values.first.is_a?(Parse::GeoPoint) && geopoint_values.last.is_a?(Parse::GeoPoint)
    raise(ArgumentError, "[Parse::Query] Invalid query value parameter passed to `within_box` constraint. " +
                         "Values in array must be `Parse::GeoPoint` objects and " +
                         "it should be in an array format: [southwestPoint, northeastPoint]")
  end
  { @operation.operand => { :$within => { :$box => geopoint_values } } }
end

#within_boxWithinGeoBoxQueryConstraint

A registered method on a symbol to create the constraint. Maps to Parse operator “$within”.

Examples:

q.where :field.within_box => [soutwestGeoPoint, northeastGeoPoint]

Returns:



651
# File 'lib/parse/query/constraints.rb', line 651

contraint_keyword :$within