query_params 1.3.3 → 1.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ace92aa8d3a7cab0655dbf2a688eb3af1313ce8f
4
- data.tar.gz: 5813633f98052701f30d04c63cc3a445ddf3dfa1
3
+ metadata.gz: 322226a09a5fb8822a75fe7edf985d0b43d9dcff
4
+ data.tar.gz: 4e665ac550f94894649871f0ed03f2448108f701
5
5
  SHA512:
6
- metadata.gz: a5d64a63802b5f6c699b165179dafbbda489a6f8272a2b08e13b631b4b73d336b8a02c0ecd5e3d278d0b3d9a3239e0e54dc5e149d76e86d22820389dc4a953fb
7
- data.tar.gz: 37351f81e693256f768a4c3d48e3e408d2b84d18006d60d0ccbdb4707926908bc75b2574ba5465cdfb3b1815dc02350806c5ce6e8024390f488bb638efda5a92
6
+ metadata.gz: 01c865f8a245237840e5b4ca897815eec27870fa1ab267d5b7a350ee2619dc2a3632d3bd7c43b3b3f04e25d4c4a54db504558b3115c6792ce5a4c2dbbe663f42
7
+ data.tar.gz: 47f2367a3cad7ba976018767c904bd94ac429fa7c007ecc8ee373315a9b3a9d27959df73374ec5b6316b178dc5d8f23d4c64670d36e6b3a3b7eca7463458f825
data/README.md CHANGED
@@ -28,8 +28,8 @@ Or install it yourself as:
28
28
 
29
29
  ```ruby
30
30
  # Only query params
31
- URI::QueryParams.filters(filters: ["type = 1", "height <= 1.8", "age between 18 and 21"])
32
- # => "type::eq(1)|height::le(1.8)|age::bt(18,21)"
31
+ URI::QueryParams.filters(filters: ["type = 1", "height <= 2", "age between 18 and 21"], "status in(1,3,5)")
32
+ # => "type::eq(1)|height::le(2)|age::bt(18,21)|status::in(1,3,5)"
33
33
 
34
34
  # Complete URI
35
35
  URI::QueryParams.build_uri(base_uri: "http://domain.com/search", q: "Mark", filters: ["age <= 18"])
@@ -2,7 +2,7 @@ require "query_params"
2
2
 
3
3
  module Condition
4
4
 
5
- OPERATORS = { "=" => "eq", ">=" => "ge", "<=" => "le", "between" => "bt" }
5
+ OPERATORS = { "=" => "eq", ">=" => "ge", "<=" => "le", "between" => "bt", "in" => "in" }
6
6
 
7
7
  def set_conditions(conditions)
8
8
 
@@ -16,9 +16,12 @@ module Condition
16
16
  end
17
17
 
18
18
  def set_query(condition)
19
+
20
+ condition = condition.gsub(/ in\(/i, ' in (')
21
+
19
22
  tokens = condition.split(" ")
20
23
 
21
- raise(ArgumentError, "Invalid condition: #{condition}. Send operator separate for space.") if tokens.size < 3
24
+ raise(ArgumentError, "Invalid condition: #{condition}. Probably, the operator was not separated by space.") if tokens.size < 3
22
25
 
23
26
  field = tokens[0].strip
24
27
  operator = tokens[1].strip.downcase
@@ -26,13 +29,16 @@ module Condition
26
29
 
27
30
  raise(ArgumentError, "Invalid operator. Accepted tokens: #{OPERATORS.values}") if OPERATORS[operator].nil?
28
31
 
29
- if operator != "between"
30
- # queryParam.eq('age', 18)
31
- self.send(OPERATORS[operator], field, value)
32
- else
32
+ if operator == "between"
33
33
  bt_values = value.downcase.split(' and ')
34
34
  # queryParam.bt('age', 18, 21)
35
35
  self.send(OPERATORS[operator], field, bt_values[0], bt_values[1])
36
+ elsif operator == "in"
37
+ # queryParam.in('age', [1,2,3])
38
+ self.send(OPERATORS[operator], field, value.strip[1..-2].split(","))
39
+ else
40
+ # queryParam.eq('age', 18)
41
+ self.send(OPERATORS[operator], field, value)
36
42
  end
37
43
  end
38
44
 
@@ -20,6 +20,10 @@ module Filter
20
20
  equal(key, value)
21
21
  end
22
22
 
23
+ def in(key, values)
24
+ @params.push("#{key}::in(#{values.join(",")})")
25
+ end
26
+
23
27
  def greater_and_equal(key, value)
24
28
  @params.push("#{key}::ge(#{value})")
25
29
  end
@@ -1,3 +1,3 @@
1
1
  module QueryParams
2
- VERSION = "1.3.3"
2
+ VERSION = "1.4.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: query_params
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.4.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Souza
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-07-14 00:00:00.000000000 Z
11
+ date: 2015-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler