Class: Condition
- Inherits:
-
Object
- Object
- Condition
- Defined in:
- lib/query_params/condition.rb
Constant Summary collapse
- OPERATORS =
{ "=" => "eq", ">=" => "ge", "<=" => "le" }
Class Method Summary collapse
Class Method Details
.build_uri(queryParams, conditions) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/query_params/condition.rb', line 7 def self.build_uri(queryParams, conditions) if conditions.kind_of?(Array) conditions.each do |condition| set_query(queryParams, condition) end else set_query(queryParams, conditions) end end |
.set_query(queryParams, condition) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/query_params/condition.rb', line 18 def self.set_query(queryParams, condition) tokens = condition.split(" ") raise(ArgumentError, "Invalid condition: #{condition}. Send operator separate for space.") if tokens.size < 3 field = tokens[0].strip operator = tokens[1].strip value = tokens[2..tokens.size].join(" ").strip.gsub(/['"]/,"") raise(ArgumentError, "Invalid operator. Accepted tokens: #{OPERATORS.values}") if OPERATORS[operator].nil? queryParams.send(OPERATORS[operator], field, value) end |