pivot_table 0.5.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 71aa891a3427082fef666c33490e4314ab6444b4
4
- data.tar.gz: c975d98e739a829c3ec502de9772b58042d22588
3
+ metadata.gz: a12fa63c469f47ac0e9abfc37e116c62ddcff0d7
4
+ data.tar.gz: 2868f37cb5693d510bd0d7b1ca5d3b3ab2c57508
5
5
  SHA512:
6
- metadata.gz: 6edc7f8e30b2d000f9d7df661ab8f43fd22c0924a5dbb09589e8858e74a84e5f52fdadcde5d7cb3a5bb58c380f6a758fc6c467ed78a70e2521b4c4e17438ad1c
7
- data.tar.gz: 0a7eeab1e957a865db8befc118876a6e23ec3bfe455515e383c94616f51de96de643658ac5e1249dfd7c75e4331b85d77c4220cda3e37c83a4e04c6ab97dc387
6
+ metadata.gz: a4288437756213dd93a0a94b703843236a6453d57b24aefc02c56e7845075eac144df67327a8eec845f064803d0f7b56a292fd5a2f6e6356ce22b3be2e03964c
7
+ data.tar.gz: 9741079b0c8f67e5bae38769b55c1e9202a8b79863c9d4045898dd9d36eb00f4826f9ffbf023fba675b05de00ab8bf46a1ba89a0b436a86789c1740bacc8306c
data/.gitignore CHANGED
@@ -1,6 +1,8 @@
1
1
  .idea
2
2
  *.gem
3
3
  .bundle
4
+ .gemtags
5
+ .tags
4
6
  Gemfile.lock
5
7
  pkg/*
6
8
  tmp
@@ -1 +1 @@
1
- 2.2.1
1
+ 2.3.0
@@ -1,3 +1,3 @@
1
1
  rvm:
2
- - 1.9.3
3
2
  - 2.2.1
3
+ - 2.3.0
data/Guardfile CHANGED
@@ -1,16 +1,8 @@
1
- # Note: The cmd option is now required due to the increasing number of ways
2
- # rspec may be run, below are examples of the most common uses.
3
- # * bundler: 'bundle exec rspec'
4
- # * bundler binstubs: 'bin/rspec'
5
- # * spring: 'bin/rsspec' (This will use spring if running and you have
6
- # installed the spring binstubs per the docs)
7
- # * zeus: 'zeus rspec' (requires the server to be started separetly)
8
- # * 'just' rspec: 'rspec'
9
- guard :rspec, cmd: 'bundle exec rspec' do
1
+ guard :rspec, cmd: 'bundle exec rspec', all_on_start: true do
2
+ clearing :on
10
3
  watch(%r{^spec/.+_spec\.rb$})
11
- watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
12
- watch(%r{^lib/pivot_table.rb$}) { "spec" }
13
- watch(%r{^lib/pivot_table/(.+)\.rb$}) { "spec" }
14
- watch('spec/spec_helper.rb') { "spec" }
4
+ watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
5
+ watch(%r{^lib/pivot_table.rb$}) { 'spec' }
6
+ watch(%r{^lib/pivot_table/(.+)\.rb$}) { 'spec' }
7
+ watch('spec/spec_helper.rb') { 'spec' }
15
8
  end
16
-
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
- # Pivot Table [![Build Status](https://secure.travis-ci.org/edjames/pivot_table.png)](http://travis-ci.org/edjames/pivot_table) [![Code Climate](https://codeclimate.com/github/edjames/pivot_table.png)](https://codeclimate.com/github/edjames/pivot_table) [![Dependency Status](https://gemnasium.com/edjames/pivot_table.png)](https://gemnasium.com/edjames/pivot_table) [![Gem Version](https://badge.fury.io/rb/pivot_table.png)](http://badge.fury.io/rb/pivot_table) [![pivot_table API Documentation](https://www.omniref.com/ruby/gems/pivot_table.png)](https://www.omniref.com/ruby/gems/pivot_table)
1
+ # Pivot Table
2
+
3
+ [![Build Status](https://secure.travis-ci.org/edjames/pivot_table.png)](http://travis-ci.org/edjames/pivot_table) [![Code Climate](https://codeclimate.com/github/edjames/pivot_table.png)](https://codeclimate.com/github/edjames/pivot_table) [![Dependency Status](https://gemnasium.com/edjames/pivot_table.png)](https://gemnasium.com/edjames/pivot_table) [![Gem Version](https://badge.fury.io/rb/pivot_table.png)](http://badge.fury.io/rb/pivot_table) [![pivot_table API Documentation](https://www.omniref.com/ruby/gems/pivot_table.png)](https://www.omniref.com/ruby/gems/pivot_table)
2
4
 
3
5
  A handy tool for transforming a dataset into a spreadsheet-style pivot table.
4
6
 
@@ -7,6 +9,14 @@ A handy tool for transforming a dataset into a spreadsheet-style pivot table.
7
9
  One of the most powerful and underrated features of spreadhseet packages is their ability to create pivot tables. I'm often asked
8
10
  to replicate this functionality in a web application, so I decided to share. This is a simple gem for a specific job, I hope it helps.
9
11
 
12
+ #### What this gem WILL do
13
+
14
+ This gem provides a simple mechanism to handle the turning of a dataset into a cross-tabular format for display purposes. The gem will make it easy to display your data in the form of a pivot table.
15
+
16
+ #### What this gem WILL NOT do
17
+
18
+ This gem is *not* a data aggregation engine (and it probably never will be). This gem expects an aggregated dataset. If you're looking for a gem to handle data aggregation then you may want to take a look at the [ruport](https://github.com/ruport/ruport) gem.
19
+
10
20
  ### Installation
11
21
 
12
22
  Couldn't be easier...
@@ -7,5 +7,5 @@ require 'pivot_table/column'
7
7
  require 'pivot_table/row'
8
8
 
9
9
  module PivotTable
10
- VERSION = '0.5.0'
10
+ VERSION = '1.0.0'
11
11
  end
@@ -22,8 +22,8 @@ module PivotTable
22
22
 
23
23
  def build_rows
24
24
  @rows = []
25
- @data_grid.each_with_index do |data, index|
26
- @rows << Row.new(
25
+ data_grid.each_with_index do |data, index|
26
+ rows << Row.new(
27
27
  :header => row_headers[index],
28
28
  :data => data,
29
29
  :value_name => value_name,
@@ -34,8 +34,8 @@ module PivotTable
34
34
 
35
35
  def build_columns
36
36
  @columns = []
37
- @data_grid.transpose.each_with_index do |data, index|
38
- @columns << Column.new(
37
+ data_grid.transpose.each_with_index do |data, index|
38
+ columns << Column.new(
39
39
  :header => column_headers[index],
40
40
  :data => data,
41
41
  :value_name => value_name,
@@ -45,11 +45,11 @@ module PivotTable
45
45
  end
46
46
 
47
47
  def column_headers
48
- @column_headers ||= headers @column_name
48
+ @column_headers ||= headers column_name
49
49
  end
50
50
 
51
51
  def row_headers
52
- @row_headers ||= headers @row_name
52
+ @row_headers ||= headers row_name
53
53
  end
54
54
 
55
55
  def column_totals
@@ -67,30 +67,51 @@ module PivotTable
67
67
  def prepare_grid
68
68
  @data_grid = []
69
69
  row_headers.count.times do
70
- @data_grid << column_headers.count.times.inject([]) { |col| col << nil }
70
+ data_grid << column_headers.count.times.inject([]) { |col| col << nil }
71
71
  end
72
- @data_grid
72
+ data_grid
73
73
  end
74
74
 
75
75
  def populate_grid
76
76
  prepare_grid
77
77
  row_headers.each_with_index do |row, row_index|
78
- current_row = []
79
- column_headers.each_with_index do |col, col_index|
80
- object = @source_data.find { |item| item.send(row_name) == row && item.send(column_name) == col }
81
- has_field_name = field_name && object.respond_to?(field_name)
82
- current_row[col_index] = has_field_name ? object.send(field_name) : object
83
- end
84
- @data_grid[row_index] = current_row
78
+ data_grid[row_index] = build_data_row(row)
85
79
  end
86
- @data_grid
80
+ data_grid
87
81
  end
88
82
 
89
83
  private
90
84
 
91
85
  def headers(method)
92
- hdrs = @source_data.collect { |c| c.send method }.uniq
86
+ hdrs = source_data.collect { |c| c.send method }.uniq
93
87
  configuration.sort ? hdrs.sort : hdrs
94
88
  end
89
+
90
+ def build_data_row(row)
91
+ current_row = []
92
+ column_headers.each_with_index do |col, col_index|
93
+ current_row[col_index] = derive_row_value(row, col)
94
+ end
95
+ current_row
96
+ end
97
+
98
+ def find_data_item(row, col)
99
+ source_data.find do |item|
100
+ item.send(row_name) == row && item.send(column_name) == col
101
+ end
102
+ end
103
+
104
+ def derive_row_value(row, col)
105
+ data_item = find_data_item(row, col)
106
+ if has_field_name?(data_item)
107
+ data_item.send(field_name)
108
+ else
109
+ data_item
110
+ end
111
+ end
112
+
113
+ def has_field_name?(data_item)
114
+ !!(field_name && data_item.respond_to?(field_name))
115
+ end
95
116
  end
96
117
  end
@@ -21,7 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
22
22
  s.require_paths = ["lib"]
23
23
 
24
- s.add_development_dependency "rspec", "~> 3.1"
24
+ s.add_development_dependency "rspec", "~> 3.4"
25
25
  s.add_development_dependency "growl", "~> 1.0"
26
- s.add_development_dependency "guard-rspec", "~> 4.3"
26
+ s.add_development_dependency "guard-rspec", "~> 4.6"
27
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pivot_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed James
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-05-29 00:00:00.000000000 Z
11
+ date: 2016-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '3.1'
19
+ version: '3.4'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '3.1'
26
+ version: '3.4'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: growl
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '4.3'
47
+ version: '4.6'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '4.3'
54
+ version: '4.6'
55
55
  description: Transform an ActiveRecord-ish data set into a pivot table of objects
56
56
  email: ed.james.email@gmail.com
57
57
  executables: []
@@ -105,10 +105,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  version: '0'
106
106
  requirements: []
107
107
  rubyforge_project: pivot_table
108
- rubygems_version: 2.4.6
108
+ rubygems_version: 2.5.1
109
109
  signing_key:
110
110
  specification_version: 4
111
- summary: pivot_table-0.5.0
111
+ summary: pivot_table-1.0.0
112
112
  test_files:
113
113
  - spec/pivot_table/column_spec.rb
114
114
  - spec/pivot_table/configuration_spec.rb