goldmine 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,7 +1,3 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
+ gemspec
2
3
 
3
- gem "minitest", :group => :test
4
- gem "turn", :group => :test
5
- gem "simplecov", :require => false, :group => :test
6
- gem "debugger", :group => :development
7
- gem "pry", :group => [:development, :test]
data/Gemfile.lock CHANGED
@@ -1,37 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ goldmine (0.9.2)
5
+
1
6
  GEM
2
- remote: http://rubygems.org/
7
+ remote: https://rubygems.org/
3
8
  specs:
4
- ansi (1.4.2)
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)
14
- method_source (0.7.1)
15
- minitest (3.1.0)
16
- multi_json (1.3.6)
17
- pry (0.9.9.6)
9
+ ansi (1.4.3)
10
+ coderay (1.0.9)
11
+ method_source (0.8.1)
12
+ minitest (4.7.2)
13
+ pry (0.9.12)
18
14
  coderay (~> 1.0.5)
19
- method_source (~> 0.7.1)
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)
25
- slop (2.4.4)
26
- turn (0.9.5)
15
+ method_source (~> 0.8)
16
+ slop (~> 3.4)
17
+ rake (10.0.4)
18
+ slop (3.4.4)
19
+ turn (0.9.6)
27
20
  ansi
28
21
 
29
22
  PLATFORMS
30
23
  ruby
31
24
 
32
25
  DEPENDENCIES
33
- debugger
26
+ goldmine!
34
27
  minitest
35
28
  pry
36
- simplecov
29
+ rake
37
30
  turn
data/README.md CHANGED
@@ -1,8 +1,14 @@
1
1
  # Goldmine
2
2
 
3
+ [![Build Status](https://travis-ci.org/hopsoft/goldmine.png)](https://travis-ci.org/hopsoft/goldmine)
4
+ [![Dependency Status](https://gemnasium.com/hopsoft/goldmine.png)](https://gemnasium.com/hopsoft/goldmine)
5
+ [![Code Climate](https://codeclimate.com/github/hopsoft/goldmine.png)](https://codeclimate.com/github/hopsoft/goldmine)
6
+
3
7
  ## Pivot tables for the Rubyist
4
8
 
5
- ### Pivot any list into a wealth of information.
9
+ ![Goldmine GEM](http://hopsoft.github.com/goldmine/images/gold.jpg)
10
+
11
+ ### Pivot any list into a wealth of information
6
12
 
7
13
  Goldmine allows you to apply pivot table logic to any list for powerful data mining capabilities.
8
14
 
@@ -19,7 +25,7 @@ Goldmine allows you to apply pivot table logic to any list for powerful data min
19
25
 
20
26
  Install
21
27
 
22
- ```
28
+ ```bash
23
29
  $gem install goldmine
24
30
  ```
25
31
 
@@ -36,7 +42,6 @@ require "goldmine"
36
42
  * [Create a named pivot](#explicitly-name-a-pivot)
37
43
  * [Pivot values that are lists themselves](#pivot-values-that-are-lists-themselves)
38
44
  * [Chain pivots](#chain-pivots-together)
39
- * [Chain pivots conditionally](#conditionally-chain-pivots-together)
40
45
  * [Dig deep and extract meaningful data](#deep-cuts)
41
46
 
42
47
  ## The Basics
@@ -114,23 +119,6 @@ data = list.pivot { |i| i < 5 }.pivot { |i| i % 2 == 0 }
114
119
  }
115
120
  ```
116
121
 
117
- ### Conditionally chain pivots together
118
-
119
- ```ruby
120
- # operation
121
- params = { :divisible_by_two => false, :next_greater_than_five => true }
122
- list = [1,2,3,4,5,6,7,8,9]
123
- data = list.pivot("less than 5") { |i| i < 5 }
124
- data = data.pivot("divisible by 2") { |i| i % 2 == 0 } if params[:divisible_by_two]
125
- data = data.pivot("next greater than 5") { |i| i.next > 5 } if params[:next_greater_than_five]
126
-
127
- # resulting data
128
- {
129
- { "less than 5" => true, "next greater than 5" => false } => [1, 2, 3, 4],
130
- { "less than 5" => false, "next greater than 5" => true } => [5, 6, 7, 8, 9]
131
- }
132
- ```
133
-
134
122
  ## Deep Cuts
135
123
 
136
124
  ### Build a moderately complex dataset of Cities
@@ -208,7 +196,7 @@ data = cities
208
196
 
209
197
  Here is a table view of the pivoted city data from above.
210
198
 
211
- <table>
199
+ <table class="table table-bordered table-striped">
212
200
  <thead>
213
201
  <tr>
214
202
  <th>state</th>
@@ -301,7 +289,7 @@ data = cities
301
289
 
302
290
  Here is the corresponding table view for the above dataset.
303
291
 
304
- <table>
292
+ <table class="table table-bordered table-striped">
305
293
  <thead>
306
294
  <tr>
307
295
  <th>airline</th>
@@ -384,6 +372,8 @@ Hopefully you can see the potential even though the above examples are somewhat
384
372
 
385
373
  * [One on One Marketing](http://www.1on1.com/) - for sponsoring the development of Goldmine
386
374
  * [Eric Berry](https://github.com/cavneb/) - for constructive feedback
375
+ * [Spencer Roan](https://github.com/spencerroan) - for constructive feedback
387
376
  * [Brian Johnson](https://github.com/whap/) - for bringing some sanity to the recursion
388
377
  * [Josh Bowles](https://github.com/jbowles/) - for early adoption and feedback
389
378
  * [Brett Beers](https://github.com/beersbr/) - for early adoption and feedback
379
+
data/Rakefile CHANGED
@@ -1,12 +1,10 @@
1
- require 'rake'
2
- require 'rake/testtask'
3
- require 'rdoc/task'
4
- require 'bundler'
5
- Bundler.require :development, :test
1
+ require "rake"
2
+ require "rake/testtask"
3
+ require "bundler/gem_tasks"
4
+
5
+ task :default => [:test]
6
6
 
7
7
  Rake::TestTask.new(:test) do |t|
8
- t.test_files = FileList['test/test_*.rb']
8
+ t.test_files = Dir["test/test_*.rb"]
9
9
  end
10
10
 
11
- task 'test:units' => ['test'] do
12
- end
data/lib/goldmine.rb CHANGED
@@ -1,136 +1,6 @@
1
- require "rubygems"
2
-
3
- # Goldmine brings pivot table behavior to Arrays.
4
- module Goldmine
5
-
6
- # Extends Array with a pivot method.
7
- module ArrayMiner
8
-
9
- # Pivots the Array into a Hash of mined data.
10
- # Think of it as creating a pivot table or perhaps an OLAP cube.
11
- #
12
- # @example Simple pivot
13
- # list = [1,2,3,4,5,6,7,8,9]
14
- # data = list.pivot { |i| i < 5 }
15
- #
16
- # # resulting data
17
- # # {
18
- # # true => [1, 2, 3, 4],
19
- # # false => [5, 6, 7, 8, 9]
20
- # # }
21
- #
22
- # @example Named pivot
23
- # list = [1,2,3,4,5,6,7,8,9]
24
- # data = list.pivot("less than 5") { |i| i < 5 }
25
- #
26
- # # resulting data
27
- # # {
28
- # # { "less than 5" => true } => [1, 2, 3, 4],
29
- # # { "less than 5" => false } => [5, 6, 7, 8, 9]
30
- # # }
31
- #
32
- # @example Chained pivot
33
- # list = [1,2,3,4,5,6,7,8,9]
34
- # data = list.pivot { |i| i < 5 }.pivot { |i| i % 2 == 0 }
35
- #
36
- # # resulting data
37
- # {
38
- # [true, false] => [1, 3],
39
- # [true, true] => [2, 4],
40
- # [false, false] => [5, 7, 9],
41
- # [false, true] => [6, 8]
42
- # }
43
- #
44
- # @param [String] name The named of the pivot.
45
- # @yield [Object] Yields once for each item in the Array
46
- # @return [Hash] The pivoted Hash of data.
47
- def pivot(name=nil, &block)
48
- reduce({}) do |memo, item|
49
- value = yield(item)
50
-
51
- if value.is_a?(Array)
52
- if value.empty?
53
- memo.assign_mined(name, nil, item)
54
- else
55
- value.each { |v| memo.assign_mined(name, v, item) }
56
- end
57
- else
58
- memo.assign_mined(name, value, item)
59
- end
60
-
61
- memo.goldmine = true
62
- memo
63
- end
64
- end
65
- end
66
-
67
- # Extends Hash with a pivot method.
68
- module HashMiner
69
-
70
- attr_accessor :goldmine
71
-
72
- # Further pivots the Hash into mined data.
73
- # This method is what enables the pivot method chaining.
74
- #
75
- # @example Chained pivot
76
- # list = [1,2,3,4,5,6,7,8,9]
77
- # data = list.pivot { |i| i < 5 }.pivot { |i| i % 2 == 0 }
78
- #
79
- # # resulting data
80
- # {
81
- # [true, false] => [1, 3],
82
- # [true, true] => [2, 4],
83
- # [false, false] => [5, 7, 9],
84
- # [false, true] => [6, 8]
85
- # }
86
- #
87
- # @note This method should not be called directly. Call Array#pivot instead.
88
- #
89
- # @param [String] name The named of the pivot.
90
- # @yield [Object] Yields once for each item in the Array
91
- # @return [Hash] The pivoted Hash of data.
92
- def pivot(name=nil, &block)
93
- return self unless goldmine
94
-
95
- reduce({}) do |memo, item|
96
- key = item.first
97
- value = item.last
98
- value.pivot(name, &block).each do |k, v|
99
- if key.is_a? Hash
100
- k = { block.to_s => k } unless k.is_a?(Hash)
101
- new_key = key.merge(k)
102
- else
103
- new_key = [key, k].flatten
104
- end
105
- memo[new_key] = v
106
- end
107
- memo.goldmine = true
108
- memo
109
- end
110
- end
111
-
112
- # Assigns a key/value pair to the Hash.
113
- # @param [String] name The name of a pivot (can be null).
114
- # @param [Object] key The key to use.
115
- # @param [Object] value The value to assign
116
- # @return [Object] The result of the assignment.
117
- def assign_mined(name, key, value)
118
- goldmine_key = goldmine_key(name, key)
119
- self[goldmine_key] ||= []
120
- self[goldmine_key] << value
121
- end
122
-
123
- # Creates a key for a pivot-name/key combo.
124
- # @param [String] name The name of a pivot (can be null).
125
- # @param [Object] key The key to use.
126
- # @return [Object] The constructed key.
127
- def goldmine_key(name, key)
128
- goldmine_key = { name => key } if name
129
- goldmine_key ||= key
130
- end
131
-
132
- end
133
- end
1
+ $:.unshift File.join(File.dirname(__FILE__), "goldmine")
2
+ require "array_miner"
3
+ require "hash_miner"
134
4
 
135
5
  ::Array.send(:include, Goldmine::ArrayMiner)
136
6
  ::Hash.send(:include, Goldmine::HashMiner)
@@ -0,0 +1,64 @@
1
+ module Goldmine
2
+
3
+ # Extends Array with a pivot method.
4
+ module ArrayMiner
5
+
6
+ # Pivots the Array into a Hash of mined data.
7
+ # Think of it as creating a pivot table or perhaps an OLAP cube.
8
+ #
9
+ # @example Simple pivot
10
+ # list = [1,2,3,4,5,6,7,8,9]
11
+ # data = list.pivot { |i| i < 5 }
12
+ #
13
+ # # resulting data
14
+ # # {
15
+ # # true => [1, 2, 3, 4],
16
+ # # false => [5, 6, 7, 8, 9]
17
+ # # }
18
+ #
19
+ # @example Named pivot
20
+ # list = [1,2,3,4,5,6,7,8,9]
21
+ # data = list.pivot("less than 5") { |i| i < 5 }
22
+ #
23
+ # # resulting data
24
+ # # {
25
+ # # { "less than 5" => true } => [1, 2, 3, 4],
26
+ # # { "less than 5" => false } => [5, 6, 7, 8, 9]
27
+ # # }
28
+ #
29
+ # @example Chained pivot
30
+ # list = [1,2,3,4,5,6,7,8,9]
31
+ # data = list.pivot { |i| i < 5 }.pivot { |i| i % 2 == 0 }
32
+ #
33
+ # # resulting data
34
+ # {
35
+ # [true, false] => [1, 3],
36
+ # [true, true] => [2, 4],
37
+ # [false, false] => [5, 7, 9],
38
+ # [false, true] => [6, 8]
39
+ # }
40
+ #
41
+ # @param [String] name The named of the pivot.
42
+ # @yield [Object] Yields once for each item in the Array
43
+ # @return [Hash] The pivoted Hash of data.
44
+ def pivot(name=nil, &block)
45
+ reduce({}) do |memo, item|
46
+ value = yield(item)
47
+
48
+ if value.is_a?(Array)
49
+ if value.empty?
50
+ memo.assign_mined(name, nil, item)
51
+ else
52
+ value.each { |v| memo.assign_mined(name, v, item) }
53
+ end
54
+ else
55
+ memo.assign_mined(name, value, item)
56
+ end
57
+
58
+ memo.goldmine = true
59
+ memo
60
+ end
61
+ end
62
+
63
+ end
64
+ end
@@ -0,0 +1,69 @@
1
+ module Goldmine
2
+
3
+ # Extends Hash with a pivot method.
4
+ module HashMiner
5
+
6
+ attr_accessor :goldmine
7
+
8
+ # Further pivots the Hash into mined data.
9
+ # This method is what enables the pivot method chaining.
10
+ #
11
+ # @example Chained pivot
12
+ # list = [1,2,3,4,5,6,7,8,9]
13
+ # data = list.pivot { |i| i < 5 }.pivot { |i| i % 2 == 0 }
14
+ #
15
+ # # resulting data
16
+ # {
17
+ # [true, false] => [1, 3],
18
+ # [true, true] => [2, 4],
19
+ # [false, false] => [5, 7, 9],
20
+ # [false, true] => [6, 8]
21
+ # }
22
+ #
23
+ # @note This method should not be called directly. Call Array#pivot instead.
24
+ #
25
+ # @param [String] name The named of the pivot.
26
+ # @yield [Object] Yields once for each item in the Array
27
+ # @return [Hash] The pivoted Hash of data.
28
+ def pivot(name=nil, &block)
29
+ return self unless goldmine
30
+
31
+ reduce({}) do |memo, item|
32
+ key = item.first
33
+ value = item.last
34
+ value.pivot(name, &block).each do |k, v|
35
+ if key.is_a? Hash
36
+ k = { block.to_s => k } unless k.is_a?(Hash)
37
+ new_key = key.merge(k)
38
+ else
39
+ new_key = [key, k].flatten
40
+ end
41
+ memo[new_key] = v
42
+ end
43
+ memo.goldmine = true
44
+ memo
45
+ end
46
+ end
47
+
48
+ # Assigns a key/value pair to the Hash.
49
+ # @param [String] name The name of a pivot (can be null).
50
+ # @param [Object] key The key to use.
51
+ # @param [Object] value The value to assign
52
+ # @return [Object] The result of the assignment.
53
+ def assign_mined(name, key, value)
54
+ goldmine_key = goldmine_key(name, key)
55
+ self[goldmine_key] ||= []
56
+ self[goldmine_key] << value
57
+ end
58
+
59
+ # Creates a key for a pivot-name/key combo.
60
+ # @param [String] name The name of a pivot (can be null).
61
+ # @param [Object] key The key to use.
62
+ # @return [Object] The constructed key.
63
+ def goldmine_key(name, key)
64
+ goldmine_key = { name => key } if name
65
+ goldmine_key ||= key
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,3 @@
1
+ module Goldmine
2
+ VERSION = "0.9.2"
3
+ end
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.1
4
+ version: 0.9.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,25 +9,105 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-20 00:00:00.000000000 Z
13
- dependencies: []
14
- description: ! ' Goldmine allows you to apply pivot table logic to any list for
15
- powerful data mining capabilities.
16
-
17
- '
12
+ date: 2013-04-19 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: minitest
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: simplecov
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: turn
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: pry
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: Pivot tables for the Rubyist.
18
95
  email:
19
96
  - natehop@gmail.com
20
97
  executables: []
21
98
  extensions: []
22
99
  extra_rdoc_files: []
23
100
  files:
101
+ - lib/goldmine/array_miner.rb
102
+ - lib/goldmine/hash_miner.rb
103
+ - lib/goldmine/version.rb
24
104
  - lib/goldmine.rb
25
105
  - Gemfile
26
106
  - Gemfile.lock
27
107
  - Rakefile
28
108
  - README.md
29
109
  - test/test_goldmine.rb
30
- homepage: http://hopsoft.github.com/goldmine/
110
+ homepage: https://github.com/hopsoft/goldmine
31
111
  licenses:
32
112
  - MIT
33
113
  post_install_message:
@@ -48,8 +128,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
48
128
  version: '0'
49
129
  requirements: []
50
130
  rubyforge_project:
51
- rubygems_version: 1.8.10
131
+ rubygems_version: 1.8.23
52
132
  signing_key:
53
133
  specification_version: 3
54
- summary: Pivot tables for the Rubyist
55
- test_files: []
134
+ summary: Pivot tables for the Rubyist.
135
+ test_files:
136
+ - test/test_goldmine.rb
137
+ has_rdoc: