goldmine 3.0.0 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +27 -12
- data/README.md +15 -28
- data/goldmine.gemspec +20 -0
- data/lib/goldmine.rb +2 -2
- data/lib/goldmine/miner.rb +3 -2
- data/lib/goldmine/pivot.rb +12 -10
- data/lib/goldmine/pivot_result.rb +4 -4
- data/lib/goldmine/rollup.rb +7 -2
- data/lib/goldmine/rollup_result.rb +1 -0
- data/lib/goldmine/version.rb +1 -1
- data/license.md +8 -0
- data/test/test_goldmine.rb +59 -42
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 91a4cbee1837e74edc8dd9979ac018ceba177aeb
|
4
|
+
data.tar.gz: 7473dafc813bcaf29eb78434823eaa1986862e09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 08488a2eb16d68db8eff60b2d71e681f57d5995ea238872213676f881f861ff8ed231e566240d43daa6b27403c0aa5e4dc790e57db027afd5a900ff81002645e
|
7
|
+
data.tar.gz: 2401ea8fb3a1e9737816819cec3cd08549c0ccd62e796ad2a75cdc690725d8a3549b350af057b8240bdb28683df7cef4a1e3a800432d27757020f830ceecf6b6
|
data/Gemfile.lock
CHANGED
@@ -8,26 +8,34 @@ GEM
|
|
8
8
|
specs:
|
9
9
|
binding_of_caller (0.7.2)
|
10
10
|
debug_inspector (>= 0.0.1)
|
11
|
-
byebug (
|
12
|
-
|
13
|
-
|
11
|
+
byebug (5.0.0)
|
12
|
+
columnize (= 0.9.0)
|
13
|
+
coderay (1.1.0)
|
14
|
+
columnize (0.9.0)
|
15
|
+
coveralls (0.8.3)
|
14
16
|
json (~> 1.8)
|
15
|
-
|
17
|
+
rest-client (>= 1.6.8, < 2)
|
18
|
+
simplecov (~> 0.10.0)
|
16
19
|
term-ansicolor (~> 1.3)
|
17
20
|
thor (~> 0.19.1)
|
18
|
-
tins (~> 1.6.0)
|
19
21
|
debug_inspector (0.0.2)
|
20
22
|
docile (1.1.5)
|
23
|
+
domain_name (0.5.25)
|
24
|
+
unf (>= 0.0.5, < 1.0.0)
|
25
|
+
http-cookie (1.0.2)
|
26
|
+
domain_name (~> 0.5)
|
21
27
|
interception (0.5)
|
22
28
|
json (1.8.3)
|
23
29
|
method_source (0.8.2)
|
30
|
+
mime-types (2.6.2)
|
31
|
+
netrc (0.10.3)
|
24
32
|
os (0.9.6)
|
25
33
|
pry (0.10.3)
|
26
34
|
coderay (~> 1.1.0)
|
27
35
|
method_source (~> 0.8.1)
|
28
36
|
slop (~> 3.4)
|
29
|
-
pry-byebug (3.
|
30
|
-
byebug (~>
|
37
|
+
pry-byebug (3.2.0)
|
38
|
+
byebug (~> 5.0)
|
31
39
|
pry (~> 0.10)
|
32
40
|
pry-rescue (1.4.2)
|
33
41
|
interception (>= 0.5)
|
@@ -44,22 +52,29 @@ GEM
|
|
44
52
|
rack (1.6.4)
|
45
53
|
rack-protection (1.5.3)
|
46
54
|
rack
|
47
|
-
rake (
|
48
|
-
|
55
|
+
rake (10.4.2)
|
56
|
+
rest-client (1.8.0)
|
57
|
+
http-cookie (>= 1.0.2, < 2.0)
|
58
|
+
mime-types (>= 1.16, < 3.0)
|
59
|
+
netrc (~> 0.7)
|
60
|
+
simplecov (0.10.0)
|
49
61
|
docile (~> 1.1.0)
|
50
62
|
json (~> 1.8)
|
51
63
|
simplecov-html (~> 0.10.0)
|
52
64
|
simplecov-html (0.10.0)
|
53
|
-
sinatra (1.4.
|
54
|
-
rack (~> 1.
|
65
|
+
sinatra (1.4.6)
|
66
|
+
rack (~> 1.4)
|
55
67
|
rack-protection (~> 1.4)
|
56
68
|
tilt (>= 1.3, < 3)
|
57
69
|
slop (3.6.0)
|
58
70
|
term-ansicolor (1.3.2)
|
59
71
|
tins (~> 1.0)
|
60
72
|
thor (0.19.1)
|
61
|
-
tilt (2.0.
|
73
|
+
tilt (2.0.1)
|
62
74
|
tins (1.6.0)
|
75
|
+
unf (0.1.4)
|
76
|
+
unf_ext
|
77
|
+
unf_ext (0.0.7.1)
|
63
78
|
|
64
79
|
PLATFORMS
|
65
80
|
ruby
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
[![Lines of Code](http://img.shields.io/badge/lines_of_code-
|
1
|
+
[![Lines of Code](http://img.shields.io/badge/lines_of_code-191-brightgreen.svg?style=flat)](http://blog.codinghorror.com/the-best-code-is-no-code-at-all/)
|
2
2
|
[![Code Status](http://img.shields.io/codeclimate/github/hopsoft/goldmine.svg?style=flat)](https://codeclimate.com/github/hopsoft/goldmine)
|
3
3
|
[![Dependency Status](http://img.shields.io/gemnasium/hopsoft/goldmine.svg?style=flat)](https://gemnasium.com/hopsoft/goldmine)
|
4
4
|
[![Build Status](http://img.shields.io/travis/hopsoft/goldmine.svg?style=flat)](https://travis-ci.org/hopsoft/goldmine)
|
@@ -35,7 +35,6 @@ list = [1,2,3,4,5,6,7,8,9]
|
|
35
35
|
|
36
36
|
Goldmine(list)
|
37
37
|
.pivot("< 5") { |i| i < 5 }
|
38
|
-
.result
|
39
38
|
.to_h
|
40
39
|
```
|
41
40
|
|
@@ -59,7 +58,6 @@ users = [
|
|
59
58
|
|
60
59
|
Goldmine(users)
|
61
60
|
.pivot(:favorite_color) { |record| record[:favorite_colors] }
|
62
|
-
.result
|
63
61
|
.to_h
|
64
62
|
```
|
65
63
|
|
@@ -85,11 +83,10 @@ users = [
|
|
85
83
|
{ :name => "Joe", :age => 18 }
|
86
84
|
]
|
87
85
|
|
88
|
-
Goldmine(users)
|
89
|
-
pivot("'e' in name") { |user| !!user[:name].match(/e/i) }
|
90
|
-
pivot("21 or over") { |user| user[:age] >= 21 }
|
91
|
-
|
92
|
-
to_h
|
86
|
+
Goldmine(users)
|
87
|
+
.pivot("'e' in name") { |user| !!user[:name].match(/e/i) }
|
88
|
+
.pivot("21 or over") { |user| user[:age] >= 21 }
|
89
|
+
.to_h
|
93
90
|
```
|
94
91
|
|
95
92
|
```ruby
|
@@ -102,8 +99,8 @@ Goldmine(users).
|
|
102
99
|
|
103
100
|
## Rollups
|
104
101
|
|
105
|
-
|
106
|
-
|
102
|
+
Rollups provide an intuitive way to aggregate pivoted data into a report friendly format.
|
103
|
+
_Think computed columns._
|
107
104
|
|
108
105
|
Rollups are `blocks` that get executed once for each pivot entry.
|
109
106
|
_They can be also be chained._
|
@@ -114,9 +111,7 @@ list = [1,2,3,4,5,6,7,8,9]
|
|
114
111
|
Goldmine(list)
|
115
112
|
.pivot("< 5") { |i| i < 5 }
|
116
113
|
.pivot("even") { |i| i % 2 == 0 }
|
117
|
-
.result
|
118
114
|
.rollup("count", &:count)
|
119
|
-
.result
|
120
115
|
.to_h
|
121
116
|
```
|
122
117
|
|
@@ -137,13 +132,11 @@ Optional caching can be used to reduce this computational overhead.
|
|
137
132
|
```ruby
|
138
133
|
list = [1,2,3,4,5,6,7,8,9]
|
139
134
|
|
140
|
-
Goldmine(list)
|
135
|
+
Goldmine(list, cache: true)
|
141
136
|
.pivot(:less_than_5) { |i| i < 5 }
|
142
|
-
.result
|
143
137
|
.rollup(:count, &:count)
|
144
138
|
.rollup(:evens) { |list| list.select { |i| i % 2 == 0 }.count }
|
145
139
|
.rollup(:even_percentage) { |list| cache[:evens] / cache[:count].to_f }
|
146
|
-
.result(cache: true)
|
147
140
|
.to_h
|
148
141
|
```
|
149
142
|
|
@@ -161,17 +154,16 @@ It's often helpful to flatten rollups into rows.
|
|
161
154
|
```ruby
|
162
155
|
list = [1,2,3,4,5,6,7,8,9]
|
163
156
|
|
164
|
-
|
157
|
+
result = Goldmine(list, cache: true)
|
165
158
|
.pivot(:less_than_5) { |i| i < 5 }
|
166
|
-
.result
|
167
159
|
.rollup(:count, &:count)
|
168
160
|
.rollup(:evens) { |list| list.select { |i| i % 2 == 0 }.count }
|
169
161
|
.rollup(:even_percentage) { |list| cache[:evens] / cache[:count].to_f }
|
170
|
-
.result
|
162
|
+
.result
|
171
163
|
```
|
172
164
|
|
173
165
|
```ruby
|
174
|
-
|
166
|
+
result.to_rows
|
175
167
|
```
|
176
168
|
|
177
169
|
```ruby
|
@@ -182,7 +174,7 @@ rollup.to_rows
|
|
182
174
|
```
|
183
175
|
|
184
176
|
```ruby
|
185
|
-
|
177
|
+
result.to_hash_rows
|
186
178
|
```
|
187
179
|
|
188
180
|
```ruby
|
@@ -202,9 +194,7 @@ list = [1,2,3,4,5,6,7,8,9]
|
|
202
194
|
Goldmine(list)
|
203
195
|
.pivot(:less_than_5) { |i| i < 5 }
|
204
196
|
.pivot(:even) { |i| i % 2 == 0 }
|
205
|
-
.
|
206
|
-
.rollup(:count, &:size)
|
207
|
-
.result
|
197
|
+
.rollup(:count, &:count)
|
208
198
|
.to_tabular
|
209
199
|
```
|
210
200
|
|
@@ -220,7 +210,7 @@ Goldmine(list)
|
|
220
210
|
|
221
211
|
### CSV
|
222
212
|
|
223
|
-
|
213
|
+
Rollups can also be converted into CSV format.
|
224
214
|
|
225
215
|
```ruby
|
226
216
|
list = [1,2,3,4,5,6,7,8,9]
|
@@ -228,10 +218,7 @@ list = [1,2,3,4,5,6,7,8,9]
|
|
228
218
|
Goldmine(list)
|
229
219
|
.pivot(:less_than_5) { |i| i < 5 }
|
230
220
|
.pivot(:even) { |i| i % 2 == 0 }
|
231
|
-
.
|
232
|
-
.rollup(:count) { |matched| matched.size }
|
233
|
-
.result
|
234
|
-
.to_csv_table
|
221
|
+
.rollup(:count, &:count)
|
235
222
|
.to_csv
|
236
223
|
```
|
237
224
|
|
data/goldmine.gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path("../lib/goldmine/version", __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.name = "goldmine"
|
5
|
+
gem.license = "MIT"
|
6
|
+
gem.version = Goldmine::VERSION
|
7
|
+
gem.authors = ["Nathan Hopkins"]
|
8
|
+
gem.email = ["natehop@gmail.com"]
|
9
|
+
gem.homepage = "https://github.com/hopsoft/goldmine"
|
10
|
+
gem.summary = "Extract a wealth of information from Arrays"
|
11
|
+
|
12
|
+
gem.files = Dir["lib/**/*.rb", "bin/*", "[A-Z]*"]
|
13
|
+
gem.test_files = Dir["test/**/*.rb"]
|
14
|
+
|
15
|
+
gem.add_development_dependency "rake"
|
16
|
+
gem.add_development_dependency "pry-test"
|
17
|
+
gem.add_development_dependency "coveralls"
|
18
|
+
gem.add_development_dependency "sinatra"
|
19
|
+
end
|
20
|
+
|
data/lib/goldmine.rb
CHANGED
data/lib/goldmine/miner.rb
CHANGED
@@ -6,11 +6,12 @@ module Goldmine
|
|
6
6
|
extend Forwardable
|
7
7
|
include Enumerable
|
8
8
|
def_delegators :@array, :each, :to_a
|
9
|
-
attr_reader :pivots
|
9
|
+
attr_reader :pivots, :cache
|
10
10
|
|
11
|
-
def initialize(array=[])
|
11
|
+
def initialize(array=[], cache: false)
|
12
12
|
@pivots = []
|
13
13
|
@array = array.to_a
|
14
|
+
@cache = cache
|
14
15
|
end
|
15
16
|
|
16
17
|
def pivot(name, &block)
|
data/lib/goldmine/pivot.rb
CHANGED
@@ -1,24 +1,28 @@
|
|
1
|
+
require "forwardable"
|
1
2
|
require "pivot_result"
|
3
|
+
require "rollup"
|
2
4
|
|
3
5
|
module Goldmine
|
4
6
|
class Pivot
|
5
|
-
|
7
|
+
extend Forwardable
|
8
|
+
def_delegators :result, :to_h, :rollup
|
9
|
+
attr_reader :miner, :name, :proc
|
6
10
|
|
7
|
-
def initialize(name,
|
8
|
-
@
|
11
|
+
def initialize(name, miner, block)
|
12
|
+
@miner = miner
|
9
13
|
@name = name
|
10
14
|
@proc = block
|
11
|
-
|
15
|
+
miner.pivots << self
|
12
16
|
end
|
13
17
|
|
14
18
|
def pivot(name, &block)
|
15
|
-
self.class.new(name,
|
19
|
+
self.class.new(name, miner, block)
|
16
20
|
end
|
17
21
|
|
18
22
|
def result
|
19
|
-
PivotResult.new.tap do |pivot_result|
|
20
|
-
|
21
|
-
key_data =
|
23
|
+
PivotResult.new(self).tap do |pivot_result|
|
24
|
+
miner.each do |item|
|
25
|
+
key_data = miner.pivots.each_with_object(key: [], keys: []) do |pivot, memo|
|
22
26
|
value = pivot.proc.call(item)
|
23
27
|
if value.is_a?(Array)
|
24
28
|
if value.empty?
|
@@ -40,8 +44,6 @@ module Goldmine
|
|
40
44
|
|
41
45
|
private
|
42
46
|
|
43
|
-
attr_reader :array_miner
|
44
|
-
|
45
47
|
def key_for(name, value)
|
46
48
|
Array.new(2).tap do |key|
|
47
49
|
key[0] = name
|
@@ -6,12 +6,12 @@ module Goldmine
|
|
6
6
|
extend Forwardable
|
7
7
|
include Enumerable
|
8
8
|
def_delegators :@hash, :[], :[]=, :each, :to_h
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :pivot, :rollups
|
10
10
|
|
11
|
-
def initialize(hash={})
|
12
|
-
@
|
11
|
+
def initialize(pivot, hash={})
|
12
|
+
@pivot = pivot
|
13
13
|
@hash = hash
|
14
|
-
@
|
14
|
+
@rollups = []
|
15
15
|
end
|
16
16
|
|
17
17
|
def rollup(name, &block)
|
data/lib/goldmine/rollup.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
+
require "forwardable"
|
1
2
|
require "rollup_clean_room"
|
2
3
|
require "rollup_result"
|
3
4
|
|
4
5
|
module Goldmine
|
5
6
|
class Rollup
|
7
|
+
extend Forwardable
|
8
|
+
def_delegators :result, :to_h, :to_rows, :to_hash_rows, :to_tabular, :to_csv_table, :to_csv
|
9
|
+
def_delegators :pivot_result, :pivot
|
6
10
|
attr_reader :name, :proc
|
7
11
|
|
8
12
|
def initialize(name, pivot_result, block)
|
@@ -17,13 +21,14 @@ module Goldmine
|
|
17
21
|
end
|
18
22
|
|
19
23
|
def result(cache: false)
|
24
|
+
perform_caching = cache || pivot.miner.cache
|
20
25
|
RollupResult.new.tap do |rollup_result|
|
21
26
|
pivot_result.each do |pivot_key, pivoted_list|
|
22
|
-
stash = {} if
|
27
|
+
stash = {} if perform_caching
|
23
28
|
pivot_result.rollups.each do |rollup|
|
24
29
|
Array.new(2).tap do |computed_value|
|
25
30
|
key = rollup.name
|
26
|
-
value = RollupCleanRoom.new(key, stash).rollup(pivoted_list, &rollup.proc) if
|
31
|
+
value = RollupCleanRoom.new(key, stash).rollup(pivoted_list, &rollup.proc) if perform_caching
|
27
32
|
value ||= rollup.proc.call(pivoted_list)
|
28
33
|
computed_value[0] = key
|
29
34
|
computed_value[1] = value
|
data/lib/goldmine/version.rb
CHANGED
data/license.md
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
# The MIT License (MIT)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
8
|
+
|
data/test/test_goldmine.rb
CHANGED
@@ -10,21 +10,24 @@ class TestGoldmine < PryTest::Test
|
|
10
10
|
|
11
11
|
test "simple pivot" do
|
12
12
|
list = [1,2,3,4,5,6,7,8,9]
|
13
|
-
|
13
|
+
actual = Goldmine(list)
|
14
|
+
.pivot("< 5") { |i| i < 5 }
|
15
|
+
.to_h
|
14
16
|
|
15
17
|
expected = {
|
16
18
|
[["< 5", true]] => [1, 2, 3, 4],
|
17
19
|
[["< 5", false]] => [5, 6, 7, 8, 9]
|
18
20
|
}
|
19
21
|
|
20
|
-
assert
|
22
|
+
assert actual == expected
|
21
23
|
end
|
22
24
|
|
23
25
|
test "chained pivots" do
|
24
26
|
list = [1,2,3,4,5,6,7,8,9]
|
25
|
-
|
27
|
+
actual = Goldmine(list)
|
26
28
|
.pivot("< 5") { |i| i < 5 }
|
27
29
|
.pivot("even") { |i| i % 2 == 0 }
|
30
|
+
.to_h
|
28
31
|
|
29
32
|
expected = {
|
30
33
|
[["< 5", true], ["even", false]] => [1, 3],
|
@@ -33,17 +36,18 @@ class TestGoldmine < PryTest::Test
|
|
33
36
|
[["< 5", false], ["even", true]] => [6, 8]
|
34
37
|
}
|
35
38
|
|
36
|
-
assert
|
39
|
+
assert actual == expected
|
37
40
|
end
|
38
41
|
|
39
42
|
test "deep chained pivots" do
|
40
43
|
list = [1,2,3,4,5,6,7,8,9]
|
41
|
-
|
44
|
+
actual = Goldmine(list)
|
42
45
|
.pivot("< 3") { |i| i < 3 }
|
43
46
|
.pivot("< 6") { |i| i < 6 }
|
44
47
|
.pivot("< 9") { |i| i < 9 }
|
45
48
|
.pivot("even") { |i| i % 2 == 0 }
|
46
49
|
.pivot("odd") { |i| i % 3 == 0 || i == 1 }
|
50
|
+
.to_h
|
47
51
|
|
48
52
|
expected = {
|
49
53
|
[["< 3", true], ["< 6", true], ["< 9", true], ["even", false], ["odd", true]] => [1],
|
@@ -57,7 +61,7 @@ class TestGoldmine < PryTest::Test
|
|
57
61
|
[["< 3", false], ["< 6", false], ["< 9", false], ["even", false], ["odd", true]] => [9]
|
58
62
|
}
|
59
63
|
|
60
|
-
assert
|
64
|
+
assert actual == expected
|
61
65
|
end
|
62
66
|
|
63
67
|
test "pivot of list values" do
|
@@ -67,8 +71,9 @@ class TestGoldmine < PryTest::Test
|
|
67
71
|
{ :name => "three", :list => [1, 2, 3] },
|
68
72
|
{ :name => "four", :list => [1, 2, 3, 4] },
|
69
73
|
]
|
70
|
-
|
74
|
+
actual = Goldmine(list)
|
71
75
|
.pivot("list value") { |record| record[:list] }
|
76
|
+
.to_h
|
72
77
|
|
73
78
|
expected = {
|
74
79
|
["list value", 1] => [{:name=>"one", :list=>[1]}, {:name=>"two", :list=>[1, 2]}, {:name=>"three", :list=>[1, 2, 3]}, {:name=>"four", :list=>[1, 2, 3, 4]}],
|
@@ -77,7 +82,7 @@ class TestGoldmine < PryTest::Test
|
|
77
82
|
["list value", 4] => [{:name=>"four", :list=>[1, 2, 3, 4]}]
|
78
83
|
}
|
79
84
|
|
80
|
-
assert
|
85
|
+
assert actual == expected
|
81
86
|
end
|
82
87
|
|
83
88
|
test "pivot of list values with empty list" do
|
@@ -88,8 +93,9 @@ class TestGoldmine < PryTest::Test
|
|
88
93
|
{ :name => "three", :list => [1, 2, 3] },
|
89
94
|
{ :name => "four", :list => [1, 2, 3, 4] },
|
90
95
|
]
|
91
|
-
|
96
|
+
actual = Goldmine(list)
|
92
97
|
.pivot("list value") { |record| record[:list] }
|
98
|
+
.to_h
|
93
99
|
|
94
100
|
expected = {
|
95
101
|
[["list value", nil]] => [{:name=>"empty", :list=>[]}],
|
@@ -99,33 +105,33 @@ class TestGoldmine < PryTest::Test
|
|
99
105
|
["list value", 4] => [{:name=>"four", :list=>[1, 2, 3, 4]}]
|
100
106
|
}
|
101
107
|
|
102
|
-
assert
|
108
|
+
assert actual == expected
|
103
109
|
end
|
104
110
|
|
105
111
|
# rollups ...................................................................
|
106
112
|
|
107
113
|
test "simple pivot rollup" do
|
108
114
|
list = [1,2,3,4,5,6,7,8,9]
|
109
|
-
|
115
|
+
actual = Goldmine(list)
|
110
116
|
.pivot("< 5") { |i| i < 5 }
|
111
|
-
.result
|
112
117
|
.rollup(:count) { |items| items.size }
|
118
|
+
.to_h
|
113
119
|
|
114
120
|
expected = {
|
115
121
|
[["< 5", true]] => [[:count, 4]],
|
116
122
|
[["< 5", false]] => [[:count, 5]]
|
117
123
|
}
|
118
124
|
|
119
|
-
assert
|
125
|
+
assert actual == expected
|
120
126
|
end
|
121
127
|
|
122
128
|
test "chained pivots rollup" do
|
123
129
|
list = [1,2,3,4,5,6,7,8,9]
|
124
|
-
|
130
|
+
actual = Goldmine(list)
|
125
131
|
.pivot("< 5") { |i| i < 5 }
|
126
132
|
.pivot("even") { |i| i % 2 == 0 }
|
127
|
-
.result
|
128
133
|
.rollup(:count) { |row| row.size }
|
134
|
+
.to_h
|
129
135
|
|
130
136
|
expected = {
|
131
137
|
[["< 5", true], ["even", false]] => [[:count, 2]],
|
@@ -134,50 +140,50 @@ class TestGoldmine < PryTest::Test
|
|
134
140
|
[["< 5", false], ["even", true]] => [[:count, 2]]
|
135
141
|
}
|
136
142
|
|
137
|
-
assert
|
143
|
+
assert actual == expected
|
138
144
|
end
|
139
145
|
|
140
146
|
test "pivot with chained rollup" do
|
141
147
|
list = [1,2,3,4,5,6,7,8,9]
|
142
148
|
list = Goldmine(list)
|
143
|
-
|
149
|
+
actual = list
|
144
150
|
.pivot("< 5") { |i| i < 5 }
|
145
|
-
.result
|
146
151
|
.rollup(:count) { |items| items.size }
|
147
152
|
.rollup(:div_by_3) { |items| items.keep_if { |i| i % 3 == 0 }.size }
|
153
|
+
.to_h
|
148
154
|
|
149
155
|
expected = {
|
150
156
|
[["< 5", true]] => [[:count, 4], [:div_by_3, 1]],
|
151
157
|
[["< 5", false]] => [[:count, 5], [:div_by_3, 2]]
|
152
158
|
}
|
153
159
|
|
154
|
-
assert
|
160
|
+
assert actual == expected
|
155
161
|
end
|
156
162
|
|
157
163
|
# to_rows ...................................................................
|
158
164
|
|
159
165
|
test "simple pivot rollup to_rows" do
|
160
166
|
list = [1,2,3,4,5,6,7,8,9]
|
161
|
-
|
167
|
+
actual = Goldmine(list)
|
162
168
|
.pivot("< 5") { |i| i < 5 }
|
163
|
-
.result
|
164
169
|
.rollup(:count) { |items| items.size }
|
170
|
+
.to_rows
|
165
171
|
|
166
172
|
expected = [
|
167
173
|
[["< 5", true], [:count, 4]],
|
168
174
|
[["< 5", false], [:count, 5]]
|
169
175
|
]
|
170
176
|
|
171
|
-
assert
|
177
|
+
assert actual == expected
|
172
178
|
end
|
173
179
|
|
174
180
|
test "chained pivots rollup to_rows" do
|
175
181
|
list = [1,2,3,4,5,6,7,8,9]
|
176
|
-
|
182
|
+
actual = Goldmine(list)
|
177
183
|
.pivot("< 5") { |i| i < 5 }
|
178
184
|
.pivot("even") { |i| i % 2 == 0 }
|
179
|
-
.result
|
180
185
|
.rollup(:count) { |row| row.size }
|
186
|
+
.to_rows
|
181
187
|
|
182
188
|
expected = [
|
183
189
|
[["< 5", true], ["even", false], [:count, 2]],
|
@@ -186,32 +192,32 @@ class TestGoldmine < PryTest::Test
|
|
186
192
|
[["< 5", false], ["even", true], [:count, 2]]
|
187
193
|
]
|
188
194
|
|
189
|
-
assert
|
195
|
+
assert actual == expected
|
190
196
|
end
|
191
197
|
|
192
198
|
test "simple pivot rollup to_hash_rows" do
|
193
199
|
list = [1,2,3,4,5,6,7,8,9]
|
194
|
-
|
200
|
+
actual = Goldmine(list)
|
195
201
|
.pivot("< 5") { |i| i < 5 }
|
196
|
-
.result
|
197
202
|
.rollup(:count) { |items| items.size }
|
203
|
+
.to_hash_rows
|
198
204
|
|
199
205
|
expected = [
|
200
206
|
{"< 5" => true, :count => 4},
|
201
207
|
{"< 5" => false, :count => 5}
|
202
208
|
]
|
203
209
|
|
204
|
-
assert
|
210
|
+
assert actual == expected
|
205
211
|
end
|
206
212
|
|
207
213
|
# to_tabular ................................................................
|
208
214
|
|
209
215
|
test "simple pivot rollup to_tabular" do
|
210
216
|
list = [1,2,3,4,5,6,7,8,9]
|
211
|
-
|
217
|
+
actual = Goldmine(list)
|
212
218
|
.pivot("< 5") { |i| i < 5 }
|
213
|
-
.result
|
214
219
|
.rollup(:count, &:size)
|
220
|
+
.to_tabular
|
215
221
|
|
216
222
|
expected = [
|
217
223
|
["< 5", :count],
|
@@ -219,16 +225,16 @@ class TestGoldmine < PryTest::Test
|
|
219
225
|
[false, 5]
|
220
226
|
]
|
221
227
|
|
222
|
-
assert
|
228
|
+
assert actual == expected
|
223
229
|
end
|
224
230
|
|
225
231
|
test "chained pivots rollup to_tabular" do
|
226
232
|
list = [1,2,3,4,5,6,7,8,9]
|
227
|
-
|
233
|
+
actual = Goldmine(list)
|
228
234
|
.pivot("< 5") { |i| i < 5 }
|
229
235
|
.pivot(:even) { |i| i % 2 == 0 }
|
230
|
-
.result
|
231
236
|
.rollup(:count, &:size)
|
237
|
+
.to_tabular
|
232
238
|
|
233
239
|
expected = [
|
234
240
|
["< 5", :even, :count],
|
@@ -238,30 +244,42 @@ class TestGoldmine < PryTest::Test
|
|
238
244
|
[false, true, 2]
|
239
245
|
]
|
240
246
|
|
241
|
-
assert
|
247
|
+
assert actual == expected
|
242
248
|
end
|
243
249
|
|
244
250
|
# to_csv_table ..............................................................
|
245
251
|
|
246
|
-
test "simple pivot rollup
|
252
|
+
test "simple pivot rollup to_csv" do
|
247
253
|
list = [1,2,3,4,5,6,7,8,9]
|
248
|
-
|
254
|
+
actual = Goldmine(list)
|
249
255
|
.pivot("< 5") { |i| i < 5 }
|
250
|
-
.result
|
251
256
|
.rollup(:count, &:size)
|
257
|
+
.to_csv
|
252
258
|
|
253
|
-
|
254
|
-
assert csv.to_s == "< 5,count\ntrue,4\nfalse,5\n"
|
259
|
+
assert actual == "< 5,count\ntrue,4\nfalse,5\n"
|
255
260
|
end
|
256
261
|
|
257
262
|
# pivot_result cache ..........................................................
|
258
263
|
|
259
|
-
test "pivot_result cache is available to rollups" do
|
264
|
+
test "pivot_result cache is available to rollups when setting on Goldmine" do
|
260
265
|
list = [1,2,3,4,5,6,7,8,9]
|
261
266
|
cached_counts = []
|
262
|
-
Goldmine(list)
|
267
|
+
Goldmine(list, cache: true)
|
263
268
|
.pivot("< 5") { |i| i < 5 }
|
269
|
+
.rollup(:count, &:size)
|
270
|
+
.rollup(:cached_count) { |_| cached_counts << cache[:count] }
|
264
271
|
.result
|
272
|
+
|
273
|
+
assert cached_counts.size == 2
|
274
|
+
assert cached_counts.first == 4
|
275
|
+
assert cached_counts.last == 5
|
276
|
+
end
|
277
|
+
|
278
|
+
test "pivot_result cache is available to rollups when setting on result" do
|
279
|
+
list = [1,2,3,4,5,6,7,8,9]
|
280
|
+
cached_counts = []
|
281
|
+
Goldmine(list)
|
282
|
+
.pivot("< 5") { |i| i < 5 }
|
265
283
|
.rollup(:count, &:size)
|
266
284
|
.rollup(:cached_count) { |_| cached_counts << cache[:count] }
|
267
285
|
.result(cache: true)
|
@@ -270,5 +288,4 @@ class TestGoldmine < PryTest::Test
|
|
270
288
|
assert cached_counts.first == 4
|
271
289
|
assert cached_counts.last == 5
|
272
290
|
end
|
273
|
-
|
274
291
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: goldmine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Hopkins
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -77,6 +77,7 @@ files:
|
|
77
77
|
- Gemfile.lock
|
78
78
|
- README.md
|
79
79
|
- Rakefile
|
80
|
+
- goldmine.gemspec
|
80
81
|
- lib/goldmine.rb
|
81
82
|
- lib/goldmine/miner.rb
|
82
83
|
- lib/goldmine/pivot.rb
|
@@ -85,6 +86,7 @@ files:
|
|
85
86
|
- lib/goldmine/rollup_clean_room.rb
|
86
87
|
- lib/goldmine/rollup_result.rb
|
87
88
|
- lib/goldmine/version.rb
|
89
|
+
- license.md
|
88
90
|
- test/test_goldmine.rb
|
89
91
|
homepage: https://github.com/hopsoft/goldmine
|
90
92
|
licenses:
|
@@ -106,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
106
108
|
version: '0'
|
107
109
|
requirements: []
|
108
110
|
rubyforge_project:
|
109
|
-
rubygems_version: 2.5.1
|
111
|
+
rubygems_version: 2.4.5.1
|
110
112
|
signing_key:
|
111
113
|
specification_version: 4
|
112
114
|
summary: Extract a wealth of information from Arrays
|