command_search 0.4.1 → 0.5.0
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/lib/command_search/aliaser.rb +4 -1
- data/lib/command_search/optimizer.rb +16 -14
- 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: f539639bfae594c29526089d4756e38c149b3a9e495b1aed57bbd8479bb89e4a
|
4
|
+
data.tar.gz: 842fcdbf6c9580ceb06f27f19e2385a1d931f6d815108e84f8d7e53b1363c801
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c4b037f4f55d67e3107d81d77074dab14dc729c8abcdc4ce7dbdd44185f2620032310e8937ba341b4eedeeac6bd02bfcae39fbdc00c32f267c4914d78357993
|
7
|
+
data.tar.gz: a1d8d5eb5f2f565835a6a2f66c96678600d96225333329f6e3a1b1f05a0106405d0cd6ee3a869951fa9f3dca142f733547d06d1292e4bdb34e6538d9cd23b169
|
@@ -37,7 +37,10 @@ module CommandSearch
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def alias(query, aliases)
|
40
|
-
|
40
|
+
return query unless aliases.any?
|
41
|
+
out = query.dup
|
42
|
+
aliases.each { |(k, v)| alias_item(out, k, v) }
|
43
|
+
out
|
41
44
|
end
|
42
45
|
end
|
43
46
|
end
|
@@ -7,37 +7,40 @@ module CommandSearch
|
|
7
7
|
next node unless node[:nest_type] == :paren || node[:nest_type] == :pipe
|
8
8
|
ands_and_ors!(node[:value])
|
9
9
|
next node[:value].first if node[:value].length < 2
|
10
|
-
node[:value]
|
10
|
+
node[:value].map! do |kid|
|
11
11
|
next kid[:value] if kid[:nest_type] == :pipe
|
12
12
|
kid
|
13
13
|
end
|
14
|
+
node[:value].flatten!
|
14
15
|
node[:value].uniq!
|
15
16
|
node
|
16
17
|
end
|
17
18
|
end
|
18
19
|
|
19
|
-
def negate_negate(ast)
|
20
|
-
ast.
|
20
|
+
def negate_negate!(ast)
|
21
|
+
ast.map! do |node|
|
21
22
|
next node unless node[:nest_type]
|
22
|
-
|
23
|
+
negate_negate!(node[:value])
|
23
24
|
next [] if node[:value] == []
|
24
25
|
type = node[:nest_type]
|
25
26
|
child_type = node[:value].first[:nest_type]
|
26
27
|
next node unless type == :minus && child_type == :minus
|
27
28
|
node[:value].first[:value]
|
28
29
|
end
|
30
|
+
ast.flatten!
|
29
31
|
end
|
30
32
|
|
31
|
-
def denest_parens(ast, parent_type = :root)
|
32
|
-
ast.
|
33
|
+
def denest_parens!(ast, parent_type = :root)
|
34
|
+
ast.map! do |node|
|
33
35
|
next node unless node[:nest_type]
|
34
|
-
|
36
|
+
denest_parens!(node[:value], node[:nest_type])
|
35
37
|
# valid_self && (valid_parent || valid_child)
|
36
38
|
if node[:nest_type] == :paren && (parent_type != :pipe || node[:value].count < 2)
|
37
39
|
next node[:value]
|
38
40
|
end
|
39
41
|
node
|
40
42
|
end
|
43
|
+
ast.flatten!
|
41
44
|
end
|
42
45
|
|
43
46
|
def remove_empty_strings!(ast)
|
@@ -48,13 +51,12 @@ module CommandSearch
|
|
48
51
|
end
|
49
52
|
|
50
53
|
def optimize(ast)
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
out
|
54
|
+
denest_parens!(ast)
|
55
|
+
remove_empty_strings!(ast)
|
56
|
+
negate_negate!(ast)
|
57
|
+
ands_and_ors!(ast)
|
58
|
+
ast.uniq!
|
59
|
+
ast
|
58
60
|
end
|
59
61
|
end
|
60
62
|
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.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zumbalogy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chronic
|