18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/query_params/condition.rb', line 18
def set_query(condition)
condition = condition.gsub(/ in\(/i, ' in (')
tokens = condition.split(" ")
raise(ArgumentError, "Invalid condition: #{condition}. Probably, the operator was not separated by space.") if tokens.size < 3
field = tokens[0].strip
operator = tokens[1].strip.downcase
value = tokens[2..tokens.size].join(" ").strip.gsub(/['"]/,"")
raise(ArgumentError, "Invalid operator. Accepted tokens: #{OPERATORS.values}") if OPERATORS[operator].nil?
if operator == "between"
bt_values = value.downcase.split(' and ')
self.send(OPERATORS[operator], field, bt_values[0], bt_values[1])
elsif operator == "in"
self.send(OPERATORS[operator], field, value.strip[1..-2].split(","))
else
self.send(OPERATORS[operator], field, value)
end
end
|