command_search 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/command_search/memory.rb +3 -3
- data/lib/command_search/mongoer.rb +22 -8
- data/lib/command_search/parser.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3f2b041b01322aa1a4075fe249d11be0c2f09162e69004904c1c8f73bc55ef8e
|
4
|
+
data.tar.gz: 86b41dffb65a45e51301c3f83d8956c8788b53f62af0e070572154d07fe12785
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6cc6ad695a6655df003d5d0741c51e588e4ec11b875bfea45a9baf2695b33cee4e9fc8591f9cd2233f6112a5ff0765fc23370e73f0ad8871e4aee5c23c120f4d
|
7
|
+
data.tar.gz: 6a040c19da93e76992bbadb4a7e8d1adfdf786fd83a8fd0fd0818691ff5349f70531ac3eaf2374c48502b979652b6adafd9acd4f422c4c543bc3f1ac20082c73
|
@@ -29,7 +29,8 @@ module CommandSearch
|
|
29
29
|
if cmd_search == cmd_search.to_i.to_s
|
30
30
|
Time.new(cmd_search) <= item_time && item_time < Time.new(cmd_search.to_i + 1)
|
31
31
|
else
|
32
|
-
|
32
|
+
time_str = cmd_search.gsub(/[\._-]/, ' ')
|
33
|
+
input_times = Chronic.parse(time_str, { guess: nil }) || Chronic.parse(cmd_search, { guess: nil })
|
33
34
|
input_times.first <= item_time && item_time < input_times.last
|
34
35
|
end
|
35
36
|
elsif val[1][:type] == :quoted_str
|
@@ -68,10 +69,9 @@ module CommandSearch
|
|
68
69
|
}
|
69
70
|
date_pick = date_start_map[node[:nest_op]]
|
70
71
|
time_str = item_val.gsub(/[\._-]/, ' ')
|
71
|
-
|
72
72
|
next Time.new(time_str) if time_str == time_str.to_i.to_s
|
73
73
|
|
74
|
-
date = Chronic.parse(time_str, { guess: nil })
|
74
|
+
date = Chronic.parse(time_str, { guess: nil }) || Chronic.parse(item_val, { guess: nil })
|
75
75
|
if date_pick == :start
|
76
76
|
date.first
|
77
77
|
else
|
@@ -4,7 +4,7 @@ module CommandSearch
|
|
4
4
|
module Mongoer
|
5
5
|
module_function
|
6
6
|
|
7
|
-
def build_search(ast_node, fields)
|
7
|
+
def build_search(ast_node, fields, command_types)
|
8
8
|
str = ast_node[:value] || ''
|
9
9
|
fields = [fields] unless fields.is_a?(Array)
|
10
10
|
if ast_node[:type] == :quoted_str
|
@@ -18,9 +18,22 @@ module CommandSearch
|
|
18
18
|
regex = /#{Regexp.escape(str)}/i
|
19
19
|
end
|
20
20
|
if ast_node[:negate]
|
21
|
-
forms = fields.map
|
21
|
+
forms = fields.map do |field|
|
22
|
+
if [Numeric, Integer].include?(command_types[field.to_sym])
|
23
|
+
{ field => { '$ne' => str } }
|
24
|
+
else
|
25
|
+
{ field => { '$not' => regex } }
|
26
|
+
end
|
27
|
+
end
|
22
28
|
else
|
23
29
|
forms = fields.map { |f| { f => regex } }
|
30
|
+
forms = fields.map do |field|
|
31
|
+
if [Numeric, Integer].include?(command_types[field.to_sym])
|
32
|
+
{ field => str }
|
33
|
+
else
|
34
|
+
{ field => regex }
|
35
|
+
end
|
36
|
+
end
|
24
37
|
end
|
25
38
|
return forms if forms.count < 2
|
26
39
|
if ast_node[:negate]
|
@@ -106,7 +119,7 @@ module CommandSearch
|
|
106
119
|
date_begin = Time.new(time_str)
|
107
120
|
date_end = Time.new(time_str.to_i + 1).yesterday
|
108
121
|
else
|
109
|
-
date = Chronic.parse(time_str, guess: nil)
|
122
|
+
date = Chronic.parse(time_str, guess: nil) || Chronic.parse(raw_val, guess: nil)
|
110
123
|
date_begin = date.begin
|
111
124
|
date_end = date.end
|
112
125
|
end
|
@@ -124,8 +137,9 @@ module CommandSearch
|
|
124
137
|
key = '$and'
|
125
138
|
end
|
126
139
|
end
|
127
|
-
|
128
|
-
|
140
|
+
if field_node[:negate] && [Numeric, Integer].include?(type)
|
141
|
+
{ key => { '$ne' => val } }
|
142
|
+
elsif field_node[:negate] && type == String
|
129
143
|
{ key => { '$not' => val } }
|
130
144
|
else
|
131
145
|
{ key => val }
|
@@ -178,7 +192,7 @@ module CommandSearch
|
|
178
192
|
key = '$' + key
|
179
193
|
val = [key, val]
|
180
194
|
key = '$expr'
|
181
|
-
elsif type
|
195
|
+
elsif [Numeric, Integer].include?(type)
|
182
196
|
if val == val.to_i.to_s
|
183
197
|
val = val.to_i
|
184
198
|
else
|
@@ -201,7 +215,7 @@ module CommandSearch
|
|
201
215
|
if time_str == time_str.to_i.to_s
|
202
216
|
date = [Time.new(time_str), Time.new(time_str.to_i + 1).yesterday]
|
203
217
|
else
|
204
|
-
date = Chronic.parse(time_str, guess: nil)
|
218
|
+
date = Chronic.parse(time_str, guess: nil) || Chronic.parse(val, guess: nil)
|
205
219
|
end
|
206
220
|
|
207
221
|
if date_pick == :start
|
@@ -224,7 +238,7 @@ module CommandSearch
|
|
224
238
|
build_searches!(x[:value], fields, command_types)
|
225
239
|
x
|
226
240
|
else
|
227
|
-
build_search(x, fields)
|
241
|
+
build_search(x, fields, command_types)
|
228
242
|
end
|
229
243
|
end
|
230
244
|
ast.flatten!
|
@@ -3,9 +3,9 @@ module CommandSearch
|
|
3
3
|
module_function
|
4
4
|
|
5
5
|
def parens_rindex(input)
|
6
|
-
open_i = input.rindex { |x| x[:value] == '(' && x[:type] == :paren}
|
6
|
+
open_i = input.rindex { |x| x[:value] == '(' && x[:type] == :paren }
|
7
7
|
return unless open_i
|
8
|
-
close_offset = input.drop(open_i).index { |x| x[:value] == ')' && x[:type] == :paren}
|
8
|
+
close_offset = input.drop(open_i).index { |x| x[:value] == ')' && x[:type] == :paren }
|
9
9
|
return unless close_offset
|
10
10
|
[open_i, close_offset + open_i]
|
11
11
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: command_search
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zumbalogy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-02-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chronic
|