searrrch 0.0.4 → 0.0.5
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 +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +5 -1
- data/lib/searrrch.rb +6 -1
- data/spec/operators_spec.rb +7 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce131dd794060fe2eb1cdb067181f1a2426cd8e5
|
4
|
+
data.tar.gz: a69626261ef3fc28e86fe2cc4b594892b69ebf9f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00b1821f3966e90002218fecb39d4aaf55c79a393b7ae0ffbc40e06cc18124ec648f2909074d195f706c0b4001fee31dfd5e0a778cea00a3cd4fbc9f874958d6
|
7
|
+
data.tar.gz: 1d4d38d2a770af633f15fac650c5b768a672e92e8f31a5abfb60eaea5f240507b5da6c675d86150747c08305656cb52145a04c85e15a08d15875fa2200aa56cb
|
data/Gemfile.lock
CHANGED
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.
|
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
|
data/spec/operators_spec.rb
CHANGED
@@ -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
|