class PrettySearch::Query

@abstract

Public Class Methods

parse(args) click to toggle source

@return [PrettySearch::Query, match]

# File lib/pretty_search/query.rb, line 7
def self.parse(args)
  parse_simple(args)
end
parse_simple(q_strs) click to toggle source

@return [PrettySearch::SimpleQuery, match]

# File lib/pretty_search/query.rb, line 13
def self.parse_simple(q_strs)
  parsed_queries = {}
  q_strs.each do |q_str|
    matches = PrettySearch::SimpleQuery::SIMPLE_PATTERN.match q_str
    if matches && matches[1] && matches[2]
      value = matches[2].strip
      if value.is_a?(String)
        value = begin
                  Integer(value)
                rescue
                  value
                end
      end
      if value.is_a?(String)
        value = begin
                  Float(value)
                rescue
                  value
                end
      end
      value = true if value == 'true'
      value = false if value == 'false'
      parsed_queries[matches[1].strip] = value
    else
      raise InvalidQuery, "Cannot understand query: #{q_str}"
    end
  end

  PrettySearch::SimpleQuery.new(parsed_queries)
end