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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7421f1700877300625859b984fbc83837f4849d5
4
- data.tar.gz: bd42c35da85afd81735aa03d211c64483f7a2b47
3
+ metadata.gz: fcc6c70aef70c015a20b523b734100d1311b6a74
4
+ data.tar.gz: 3f21113f8d1fac514461b4e55256612e08ad4ad9
5
5
  SHA512:
6
- metadata.gz: a9f5bfee12c8f9fb4e67fe88e442ecde36028028e6381716b0dde0a387770b7bf3fe14c5b696200eb6948a2d699018f26e39348a1c57aef1e5f6f650fb21237c
7
- data.tar.gz: 67a6fd81116bd17f4601b51c363919b8d5b8b1537b691d90c6e9a5d2a58fef97dbc9b05e620de610212c704af0addc921a9116101cb4eb15aa7584f1066669c7
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
+ ```
@@ -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
- def to_a
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
@@ -1,3 +1,3 @@
1
1
  module Goldmine
2
- VERSION = "1.1.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -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"], [false, true, 2], [true, true, 2], [true, false, 1]]
71
- assert mined.to_a == expected
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: goldmine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins