lib/mongo-parser-rb/query.rb
# Parse a query, returning an initialized MongoParserRB::Query object.
#
# @param raw_query [Hash] the hash to parse
# @return [MongoParserRB::Query] initialized query object
Parse a query, returning an initialized MongoParserRB::Query object.
Parse a query returning an initialized MongoParserRB :: Query object .
def parse_sub_expression(key, value, field = nil)
      if Expression.operator?(key)
        case key 
        when *Expression.conjunction_operators
          Expression.new(key, value.map { |v| parse_root_expression(v) })
        when *Expression.inversion_operators
          if value.kind_of?(Hash)
            Expression.new(:$not, field, parse_root_expression(value, field))
          else
            Expression.new(:$not, field, Expression.new(:$eq, field, value))
          end
        when *Expression.elemMatch_operators
          Expression.new(:$elemMatch, field, value.to_a.map do |(key, value)|
            parse_sub_expression(key, value)
          end)
        else
          Expression.new(key, field, value)
        end
      elsif value.kind_of?(Hash)
        parse_root_expression(value, key)
      else
        Expression.new(:$eq, key, value)
      end
    end
def parse_sub_expression ( key , value , field = nil ) if Expression . operator? ( key ) case key when * Expression . conjunction_operators Expression . new ( key , value . map { | v | parse_root_expression ( v ) } ) when * Expression . inversion_operators if value . kind_of? ( Hash ) Expression . new ( :$not , field , parse_root_expression ( value , field ) ) else Expression . new ( :$not , field , Expression . new ( :$eq , field , value ) ) end when * Expression . elemMatch_operators Expression . new ( :$elemMatch , field , value . to_a . map do | ( key , value ) | parse_sub_expression ( key , value ) end ) else Expression . new ( key , field , value ) end elsif value . kind_of? ( Hash ) parse_root_expression ( value , key ) else Expression . new ( :$eq , key , value ) end end
Parse a query, returning an initialized MongoParserRB::Query object.
Parse a query returning an initialized MongoParserRB :: Query object .
initialized query object
initialized query object
MongoParserRB::Query
key
<not_specific>
value
<not_specific>
field
<not_specific>
raw_query
<not_specific>
the hash to parse
the hash to parse