searrrch 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e77f9cbe9ea3dcc47a1e5f2131d7b14c23941a2
4
- data.tar.gz: 2d6c952923e46581935cb4198dfb95fc9e286814
3
+ metadata.gz: ce131dd794060fe2eb1cdb067181f1a2426cd8e5
4
+ data.tar.gz: a69626261ef3fc28e86fe2cc4b594892b69ebf9f
5
5
  SHA512:
6
- metadata.gz: ff903fa346b90435014938dca517748ebe8b53ad127bb8758bac65af8e1df5aa1c950103a4d88639aae85857c86f9ce636ee7be021849a0319d2fe5f534f78e0
7
- data.tar.gz: ba11675321951b27fe94ad6091b5df4220db246bb1594f4488d5b2cb401d7ec585f36c40b17bf69ff70c9e977db2dec607ee7ac4fe4f62d44374936569b9933f
6
+ metadata.gz: 00b1821f3966e90002218fecb39d4aaf55c79a393b7ae0ffbc40e06cc18124ec648f2909074d195f706c0b4001fee31dfd5e0a778cea00a3cd4fbc9f874958d6
7
+ data.tar.gz: 1d4d38d2a770af633f15fac650c5b768a672e92e8f31a5abfb60eaea5f240507b5da6c675d86150747c08305656cb52145a04c85e15a08d15875fa2200aa56cb
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- searrrch (0.0.4)
4
+ searrrch (0.0.5)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -16,7 +16,7 @@ The user can also put the value between quotes, in which case nested escaped quo
16
16
  Usage:
17
17
 
18
18
  ```ruby
19
- search = Searrrch.new 'user_id: 123 user_id: 124 free text here'
19
+ search = Searrrch.new 'user_id: 123 user_id: 124 status: new status: closed free text here'
20
20
  search.each_value(:user_id, :integer) do |val|
21
21
  # this block will be called twice with val being set to '123' and '124'
22
22
  end
@@ -24,6 +24,9 @@ end
24
24
  # this return all values from user_id in an array
25
25
  search.to_array(:user_id)
26
26
 
27
+ # next, return [1,2]
28
+ search.to_array(:status, { new: 1, closed: 2 })
29
+
27
30
  # or, if you preffer:
28
31
  search.as_array(:user_id) do |user_ids|
29
32
  # this is called once and only if user_id is set
@@ -49,6 +52,7 @@ Each method supports a 2nd optional parameter indicating the expected format of
49
52
 
50
53
  * :string (default)
51
54
  * :integer
55
+ * hash containing translation of the values - if not found return `nil`
52
56
  * rails model (well, anything with `.find` method)
53
57
 
54
58
  ## Installing
data/lib/searrrch.rb CHANGED
@@ -12,7 +12,7 @@ class Searrrch
12
12
  # also support ',' for you cool kids that expect something like a "list of ids"
13
13
  # 3. and also accept any char if quoted - in which case the same quotation should be quoted as well
14
14
 
15
- VERSION = '0.0.4'
15
+ VERSION = '0.0.5'
16
16
 
17
17
  # iterates over the entire string identifying each of the elements
18
18
  # this code only checks for:
@@ -81,6 +81,11 @@ class Searrrch
81
81
  return value
82
82
  when :integer
83
83
  return value.to_i
84
+ end
85
+
86
+ if expects.is_a?(Hash)
87
+ return expects[value] if expects.has_key?(value)
88
+ return expects[value.to_sym] if expects.has_key?(value.to_sym)
84
89
  else
85
90
  return expects.find(value) if defined? expects.find
86
91
  end
@@ -107,4 +107,11 @@ RSpec.describe 'operators' do
107
107
  expect(0).to eq [1,2,3,4]
108
108
  end
109
109
  end
110
+
111
+ it 'uses a translation hash' do
112
+ query = 'status: new,closed'
113
+ search = Searrrch.new query, true
114
+ translation = { new: 1, 'closed' => 2 }
115
+ expect(search.to_array(:status, translation)).to eq([1,2])
116
+ end
110
117
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: searrrch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcelo Coraça de Freitas