goldmine 1.1.1 → 1.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -0
- data/lib/goldmine/hash_miner.rb +3 -1
- data/lib/goldmine/version.rb +1 -1
- data/test/test_goldmine.rb +8 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fcc6c70aef70c015a20b523b734100d1311b6a74
|
4
|
+
data.tar.gz: 3f21113f8d1fac514461b4e55256612e08ad4ad9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 527ce95854acbd18e9665a4f78b1b63a810e9be136c8100e9081f17c5b8d4cc7ebc078e62ccfda684c7662e79656d0c9c0ddf816497cb393f6b22e5218bfcd0f
|
7
|
+
data.tar.gz: 8701ad56f3e65377c66bbfd0392bb206e1226db31211e571398d8dd7ea145cacfb2e45b970fc244d2ecddb1fcd58d0dced3a494393c360878a321e775c890703
|
data/README.md
CHANGED
@@ -161,3 +161,12 @@ mined.to_a
|
|
161
161
|
The first entry is the header row.
|
162
162
|
Subsequent entries are data rows.
|
163
163
|
The last value in each data row indicates the number of matches.
|
164
|
+
|
165
|
+
Need to sort the rows? Just pass a `sort_by` block.
|
166
|
+
|
167
|
+
```ruby
|
168
|
+
# sort on "total" i.e. 3rd value in the row
|
169
|
+
mined.to_a do |row|
|
170
|
+
row[2]
|
171
|
+
end
|
172
|
+
```
|
data/lib/goldmine/hash_miner.rb
CHANGED
@@ -79,13 +79,15 @@ module Goldmine
|
|
79
79
|
|
80
80
|
# Returns pivoted data as a tabular Array that can be used to build CSVs or user interfaces.
|
81
81
|
# @return [Array] Tabular pivot data
|
82
|
-
|
82
|
+
# @yield [Array] sort_by block for sorting the Array
|
83
|
+
def to_a(&block)
|
83
84
|
rows = map do |pair|
|
84
85
|
[].tap do |row|
|
85
86
|
row.concat pair.first.values
|
86
87
|
row << pair.last.size
|
87
88
|
end
|
88
89
|
end
|
90
|
+
rows = rows.sort_by(&block) if block_given?
|
89
91
|
header = pivoted_keys.map(&:to_s) << "total"
|
90
92
|
rows.insert 0, header
|
91
93
|
rows
|
data/lib/goldmine/version.rb
CHANGED
data/test/test_goldmine.rb
CHANGED
@@ -67,8 +67,14 @@ class TestGoldmine < PryTest::Test
|
|
67
67
|
record[:age] >= 21
|
68
68
|
end
|
69
69
|
|
70
|
-
expected = [["Name has an 'e'", ">= 21 years old", "total"], [
|
71
|
-
|
70
|
+
expected = [["Name has an 'e'", ">= 21 years old", "total"], [true, false, 1], [false, true, 2], [true, true, 2]]
|
71
|
+
|
72
|
+
# block is sort_by
|
73
|
+
tabular_data = mined.to_a do |row|
|
74
|
+
[row[2], row[0] ? 1 : 0, row[1] ? 1 : 0]
|
75
|
+
end
|
76
|
+
|
77
|
+
assert tabular_data == expected
|
72
78
|
end
|
73
79
|
|
74
80
|
test "source_data" do
|