goldmine 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,4 +2,6 @@ source :rubygems
2
2
 
3
3
  gem "minitest", :group => :test
4
4
  gem "turn", :group => :test
5
+ gem "simplecov", :require => false, :group => :test
6
+ gem "debugger", :group => :development
5
7
  gem "pry", :group => [:development, :test]
@@ -3,12 +3,25 @@ GEM
3
3
  specs:
4
4
  ansi (1.4.2)
5
5
  coderay (1.0.6)
6
+ columnize (0.3.6)
7
+ debugger (1.1.4)
8
+ columnize (>= 0.3.1)
9
+ debugger-linecache (~> 1.1.1)
10
+ debugger-ruby_core_source (~> 1.1.3)
11
+ debugger-linecache (1.1.1)
12
+ debugger-ruby_core_source (>= 1.1.1)
13
+ debugger-ruby_core_source (1.1.3)
6
14
  method_source (0.7.1)
7
15
  minitest (3.1.0)
16
+ multi_json (1.3.6)
8
17
  pry (0.9.9.6)
9
18
  coderay (~> 1.0.5)
10
19
  method_source (~> 0.7.1)
11
20
  slop (>= 2.4.4, < 3)
21
+ simplecov (0.6.4)
22
+ multi_json (~> 1.0)
23
+ simplecov-html (~> 0.5.3)
24
+ simplecov-html (0.5.3)
12
25
  slop (2.4.4)
13
26
  turn (0.9.5)
14
27
  ansi
@@ -17,6 +30,8 @@ PLATFORMS
17
30
  ruby
18
31
 
19
32
  DEPENDENCIES
33
+ debugger
20
34
  minitest
21
35
  pry
36
+ simplecov
22
37
  turn
data/README.md CHANGED
@@ -26,6 +26,7 @@ $gem install goldmine
26
26
  Use
27
27
 
28
28
  ```ruby
29
+ require "goldmine"
29
30
  [1,2,3,4,5,6,7,8,9].pivot { |i| i < 5 }
30
31
  ```
31
32
 
@@ -381,7 +382,8 @@ Hopefully you can see the potential even though the above examples are somewhat
381
382
 
382
383
  ## Special thanks
383
384
 
384
- * One on One Marketing - for sponsoring the development of Goldmine
385
- * Eric Berry - for constructive feedback
386
- * Josh Bowles - for early adoption and feedback
387
- * Brett Beers - for early adoption and feedback
385
+ * [One on One Marketing](http://www.1on1.com/) - for sponsoring the development of Goldmine
386
+ * [Eric Berry](https://github.com/cavneb/) - for constructive feedback
387
+ * [Brian Johnson](https://github.com/whap/) - for bringing some sanity to the recursion
388
+ * [Josh Bowles](https://github.com/jbowles/) - for early adoption and feedback
389
+ * [Brett Beers](https://github.com/beersbr/) - for early adoption and feedback
@@ -91,6 +91,7 @@ module Goldmine
91
91
  # @return [Hash] The pivoted Hash of data.
92
92
  def pivot(name=nil, &block)
93
93
  return self unless goldmine
94
+
94
95
  reduce({}) do |memo, item|
95
96
  key = item.first
96
97
  value = item.last
@@ -99,8 +100,7 @@ module Goldmine
99
100
  k = { block.to_s => k } unless k.is_a?(Hash)
100
101
  new_key = key.merge(k)
101
102
  else
102
- new_key = key.push(k) if key.is_a?(Array)
103
- new_key ||= [key, k]
103
+ new_key = [key, k].flatten
104
104
  end
105
105
  memo[new_key] = v
106
106
  end
@@ -1,3 +1,5 @@
1
+ require "simplecov"
2
+ SimpleCov.start
1
3
  require "test/unit"
2
4
  require "turn"
3
5
  require File.join(File.dirname(__FILE__), "..", "lib", "goldmine")
@@ -68,22 +70,47 @@ class TestGoldmine < MiniTest::Unit::TestCase
68
70
  end
69
71
 
70
72
  def test_deep_chained_pivots
73
+ list = [1,2,3,4,5,6,7,8,9]
74
+ # list = [2,5,9]
75
+ data = list
76
+ .pivot { |i| i < 3 }
77
+ .pivot { |i| i < 6 }
78
+ .pivot { |i| i < 9 }
79
+ .pivot { |i| i % 2 == 0 }
80
+ .pivot { |i| i % 3 == 0 }
81
+
82
+ expected = {
83
+ [true, true, true, false, false] => [1],
84
+ [true, true, true, true, false] => [2],
85
+ [false, true, true, false, true] => [3],
86
+ [false, true, true, false, false] => [5],
87
+ [false, true, true, true, false] => [4],
88
+ [false, false, true, true, true] => [6],
89
+ [false, false, true, true, false] => [8],
90
+ [false, false, true, false, false] => [7],
91
+ [false, false, false, false, true] => [9]
92
+ }
93
+
94
+ assert_equal expected, data
95
+ end
96
+
97
+ def test_named_deep_chained_pivots
71
98
  list = [1,2,3,4,5,6,7,8,9]
72
99
  data = list.pivot("a") { |i| i < 3 }.pivot("b") { |i| i < 6 }.pivot("c") { |i| i < 9 }.pivot("d") { |i| i % 2 == 0 }.pivot("e") { |i| i % 3 == 0 }
73
100
 
74
- expected1 = {
75
- {"a"=>true, "b"=>true, "c"=>true, "d"=>false, "e"=>false}=>[1],
76
- {"a"=>true, "b"=>true, "c"=>true, "d"=>true, "e"=>false}=>[2],
77
- {"a"=>false, "b"=>true, "c"=>true, "d"=>false, "e"=>true}=>[3],
78
- {"a"=>false, "b"=>true, "c"=>true, "d"=>false, "e"=>false}=>[5],
79
- {"a"=>false, "b"=>true, "c"=>true, "d"=>true, "e"=>false}=>[4],
80
- {"a"=>false, "b"=>false, "c"=>true, "d"=>true, "e"=>true}=>[6],
81
- {"a"=>false, "b"=>false, "c"=>true, "d"=>true, "e"=>false}=>[8],
82
- {"a"=>false, "b"=>false, "c"=>true, "d"=>false, "e"=>false}=>[7],
83
- {"a"=>false, "b"=>false, "c"=>false, "d"=>false, "e"=>true}=>[9]
101
+ expected = {
102
+ {"a"=>true, "b"=>true, "c"=>true, "d"=>false, "e"=>false} => [1],
103
+ {"a"=>true, "b"=>true, "c"=>true, "d"=>true, "e"=>false} => [2],
104
+ {"a"=>false, "b"=>true, "c"=>true, "d"=>false, "e"=>true} => [3],
105
+ {"a"=>false, "b"=>true, "c"=>true, "d"=>false, "e"=>false} => [5],
106
+ {"a"=>false, "b"=>true, "c"=>true, "d"=>true, "e"=>false} => [4],
107
+ {"a"=>false, "b"=>false, "c"=>true, "d"=>true, "e"=>true} => [6],
108
+ {"a"=>false, "b"=>false, "c"=>true, "d"=>true, "e"=>false} => [8],
109
+ {"a"=>false, "b"=>false, "c"=>true, "d"=>false, "e"=>false} => [7],
110
+ {"a"=>false, "b"=>false, "c"=>false, "d"=>false, "e"=>true} => [9]
84
111
  }
85
112
 
86
- assert_equal expected1, data
113
+ assert_equal expected, data
87
114
  end
88
115
 
89
116
  def test_named_chained_pivots
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: 0.9.0
4
+ version: 0.9.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: