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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b07ac2724b698183ea63b0ed1ad097bc6374942dde82a7cda70059b9f7a646ab
4
- data.tar.gz: b99eea79391ad07bdafa18377bb0912b4056ea89639a19124b845e79842dc395
3
+ metadata.gz: f539639bfae594c29526089d4756e38c149b3a9e495b1aed57bbd8479bb89e4a
4
+ data.tar.gz: 842fcdbf6c9580ceb06f27f19e2385a1d931f6d815108e84f8d7e53b1363c801
5
5
  SHA512:
6
- metadata.gz: 2d016c1b65bb7938675ec6423537f25cbf633ff125abc06f53c7229510a2fc967a8051e1e35d524b2c75cd902b9ba78982ea7696fb899162b95f303abe41142d
7
- data.tar.gz: f2e1cd132aea6431ecfb7e63f0ce15532730ad7705a215346178a6bd9f50532eb30329bf55cbcfb41086afee7cc7564abba1f940caecd0c91f9fa689e9ff1f49
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
- aliases.reduce(query) { |q, (k, v)| alias_item(q, k, v) }
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] = node[:value].flat_map do |kid|
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.flat_map do |node|
20
+ def negate_negate!(ast)
21
+ ast.map! do |node|
21
22
  next node unless node[:nest_type]
22
- node[:value] = negate_negate(node[:value])
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.flat_map do |node|
33
+ def denest_parens!(ast, parent_type = :root)
34
+ ast.map! do |node|
33
35
  next node unless node[:nest_type]
34
- node[:value] = denest_parens(node[:value], node[:nest_type])
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
- out = ast
52
- out = denest_parens(out)
53
- remove_empty_strings!(out)
54
- out = negate_negate(out)
55
- ands_and_ors!(out)
56
- out.uniq!
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.1
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-28 00:00:00.000000000 Z
11
+ date: 2018-11-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chronic