qo 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/README.md +3 -3
- data/lib/qo/matcher.rb +11 -11
- data/lib/qo/version.rb +1 -1
- data/performance_report.txt +24 -24
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 19be813c32add1fbe376c08a27533e43ca87254aca1b5bd73f146df70408d833
|
4
|
+
data.tar.gz: 7876f56688b5a11d0821f368bfbd612c56ecb5e08fdf2dccca6e030d56449a2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a13e4be4641782a63e1208053c7e35ee77c665ee5eff80b78af54a43f7e4254bd808a4dc6420c9c7e8bdb8c1070c36134f7192934c8c43c7169be0db81c051c8
|
7
|
+
data.tar.gz: 2098317ea5c317a86107902504787a4d47aec8e69e204490bbf72438d2f210a9bd86377b0895672e33bdf4ab8700fc5f26fade3e871d31bd329e0e86050f6711
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -490,7 +490,7 @@ There are a few functions added for convenience, and it should be noted that bec
|
|
490
490
|
|
491
491
|
#### 6.1 - Dig
|
492
492
|
|
493
|
-
Dig is used to get in deep at a nested hash value. It takes a dot-path and a `===`
|
493
|
+
Dig is used to get in deep at a nested hash value. It takes a dot-path and a `===` respondent matcher:
|
494
494
|
|
495
495
|
```ruby
|
496
496
|
Qo.dig('a.b.c', Qo.or(1..5, 15..25)) === {a: {b: {c: 1}}}
|
@@ -585,9 +585,9 @@ hosts.select(&Qo[IPAddr.new('192.168.1.1/8')])
|
|
585
585
|
=> [["192.168.1.1", "(Router)"], ["192.168.1.2", "(My Computer)"]]
|
586
586
|
```
|
587
587
|
|
588
|
-
##### 5.2.2 - `
|
588
|
+
##### 5.2.2 - `df`
|
589
589
|
|
590
|
-
The nice thing about Unix style commands is that they use headers, which means CSV can get a hold of them for some good formatting. It's also smart enough to deal with space
|
590
|
+
The nice thing about Unix style commands is that they use headers, which means CSV can get a hold of them for some good formatting. It's also smart enough to deal with space separators that may vary in length:
|
591
591
|
|
592
592
|
```ruby
|
593
593
|
rows = CSV.new(`df -h`, col_sep: " ", headers: true).read.map(&:to_h)
|
data/lib/qo/matcher.rb
CHANGED
@@ -42,8 +42,8 @@ module Qo
|
|
42
42
|
# Array -> Bool # Tuple match against targets index
|
43
43
|
# Object -> Bool # Boolean public send
|
44
44
|
private def match_against_array(matchers)
|
45
|
-
|
46
|
-
|
45
|
+
Proc.new { |match_target|
|
46
|
+
next true if matchers == match_target
|
47
47
|
|
48
48
|
match_target.is_a?(::Array) ?
|
49
49
|
match_with(matchers.each_with_index, array_against_array_matcher(match_target)) :
|
@@ -61,8 +61,8 @@ module Qo
|
|
61
61
|
# Hash -> Bool # Value matching against similar keys, will attempt to coerce to_s because JSON
|
62
62
|
# Object -> Bool # Uses keys as methods with public send to `===` match against the value
|
63
63
|
private def match_against_hash(matchers)
|
64
|
-
|
65
|
-
|
64
|
+
Proc.new { |match_target|
|
65
|
+
next true if matchers == match_target
|
66
66
|
|
67
67
|
match_target.is_a?(::Hash) ?
|
68
68
|
match_with(matchers, hash_against_hash_matcher(match_target)) :
|
@@ -91,7 +91,7 @@ module Qo
|
|
91
91
|
# @return [Proc]
|
92
92
|
# Any -> Int -> Bool # Match against wildcard or same position in target array
|
93
93
|
private def array_against_array_matcher(match_target)
|
94
|
-
|
94
|
+
Proc.new { |matcher, i|
|
95
95
|
wildcard_match(matcher) ||
|
96
96
|
case_match(match_target[i], matcher) ||
|
97
97
|
method_matches?(match_target[i], matcher)
|
@@ -105,7 +105,7 @@ module Qo
|
|
105
105
|
# @return [Proc]
|
106
106
|
# String | Symbol -> Bool # Match against wildcard or boolean return of a predicate method
|
107
107
|
private def array_against_object_matcher(match_target)
|
108
|
-
|
108
|
+
Proc.new { |matcher|
|
109
109
|
wildcard_match(matcher) ||
|
110
110
|
case_match(match_target, matcher) ||
|
111
111
|
method_matches?(match_target, matcher)
|
@@ -119,12 +119,12 @@ module Qo
|
|
119
119
|
# @return [Proc]
|
120
120
|
# Any -> Any -> Bool # Matches against wildcard or a key and value. Coerces key to_s if no matches for JSON.
|
121
121
|
private def hash_against_hash_matcher(match_target)
|
122
|
-
|
123
|
-
|
122
|
+
Proc.new { |(match_key, match_value)|
|
123
|
+
next false unless match_target.key?(match_key)
|
124
124
|
|
125
125
|
# If both the match value and target are hashes, descend if the key exists
|
126
126
|
if match_value.is_a?(Hash) && match_target.is_a?(Hash)
|
127
|
-
|
127
|
+
next match_against_hash(match_value)[match_target[match_key]]
|
128
128
|
end
|
129
129
|
|
130
130
|
wildcard_match(match_value) ||
|
@@ -146,8 +146,8 @@ module Qo
|
|
146
146
|
# @return [Proc]
|
147
147
|
# Any -> Any -> Bool # Matches against wildcard or match value versus the public send return of the target
|
148
148
|
private def hash_against_object_matcher(match_target)
|
149
|
-
|
150
|
-
|
149
|
+
Proc.new { |(match_key, match_value)|
|
150
|
+
next false unless match_target.respond_to?(match_key)
|
151
151
|
|
152
152
|
wildcard_match(match_value) ||
|
153
153
|
case_match(method_send(match_target, match_key), match_value) ||
|
data/lib/qo/version.rb
CHANGED
data/performance_report.txt
CHANGED
@@ -3,58 +3,58 @@ Array * Array - Literal
|
|
3
3
|
=======================
|
4
4
|
|
5
5
|
Warming up --------------------------------------
|
6
|
-
Vanilla
|
7
|
-
Qo.and
|
6
|
+
Vanilla 255.131k i/100ms
|
7
|
+
Qo.and 36.805k i/100ms
|
8
8
|
Calculating -------------------------------------
|
9
|
-
Vanilla
|
10
|
-
Qo.and
|
9
|
+
Vanilla 8.462M (± 2.6%) i/s - 42.352M in 5.008310s
|
10
|
+
Qo.and 454.565k (± 1.8%) i/s - 2.282M in 5.021661s
|
11
11
|
|
12
12
|
Comparison:
|
13
|
-
Vanilla:
|
14
|
-
Qo.and:
|
13
|
+
Vanilla: 8462330.9 i/s
|
14
|
+
Qo.and: 454565.2 i/s - 18.62x slower
|
15
15
|
|
16
16
|
|
17
17
|
Array * Array - Index pattern match
|
18
18
|
===================================
|
19
19
|
|
20
20
|
Warming up --------------------------------------
|
21
|
-
Vanilla 46.
|
22
|
-
Qo.and
|
21
|
+
Vanilla 46.834k i/100ms
|
22
|
+
Qo.and 13.827k i/100ms
|
23
23
|
Calculating -------------------------------------
|
24
|
-
Vanilla
|
25
|
-
Qo.and
|
24
|
+
Vanilla 551.426k (± 1.6%) i/s - 2.763M in 5.012355s
|
25
|
+
Qo.and 146.762k (± 2.3%) i/s - 746.658k in 5.090187s
|
26
26
|
|
27
27
|
Comparison:
|
28
|
-
Vanilla:
|
29
|
-
Qo.and:
|
28
|
+
Vanilla: 551426.2 i/s
|
29
|
+
Qo.and: 146762.1 i/s - 3.76x slower
|
30
30
|
|
31
31
|
|
32
32
|
Array * Object - Predicate match
|
33
33
|
================================
|
34
34
|
|
35
35
|
Warming up --------------------------------------
|
36
|
-
Vanilla
|
37
|
-
Qo.and
|
36
|
+
Vanilla 133.668k i/100ms
|
37
|
+
Qo.and 18.746k i/100ms
|
38
38
|
Calculating -------------------------------------
|
39
|
-
Vanilla 2.
|
40
|
-
Qo.and
|
39
|
+
Vanilla 2.198M (± 3.1%) i/s - 11.094M in 5.053049s
|
40
|
+
Qo.and 208.117k (± 5.4%) i/s - 1.050M in 5.059694s
|
41
41
|
|
42
42
|
Comparison:
|
43
|
-
Vanilla:
|
44
|
-
Qo.and:
|
43
|
+
Vanilla: 2197719.6 i/s
|
44
|
+
Qo.and: 208116.8 i/s - 10.56x slower
|
45
45
|
|
46
46
|
|
47
47
|
Array * Array - Select index pattern match
|
48
48
|
==========================================
|
49
49
|
|
50
50
|
Warming up --------------------------------------
|
51
|
-
Vanilla
|
52
|
-
Qo.and 20.
|
51
|
+
Vanilla 13.222k i/100ms
|
52
|
+
Qo.and 20.029k i/100ms
|
53
53
|
Calculating -------------------------------------
|
54
|
-
Vanilla
|
55
|
-
Qo.and
|
54
|
+
Vanilla 140.225k (± 3.0%) i/s - 700.766k in 5.002204s
|
55
|
+
Qo.and 217.401k (± 8.2%) i/s - 1.082M in 5.036013s
|
56
56
|
|
57
57
|
Comparison:
|
58
|
-
Qo.and:
|
59
|
-
Vanilla:
|
58
|
+
Qo.and: 217401.0 i/s
|
59
|
+
Vanilla: 140224.8 i/s - 1.55x slower
|
60
60
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: qo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Weaver
|
@@ -142,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
142
|
version: '0'
|
143
143
|
requirements: []
|
144
144
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.
|
145
|
+
rubygems_version: 2.7.6
|
146
146
|
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: Qo is a querying library for Ruby pattern matching
|