pivot_table 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f8b35be064e1f9bfb58e308e4b702c61e5b1621f
4
+ data.tar.gz: f02b0339418df01e332c6cd2743e1fcd137ec6fa
5
+ SHA512:
6
+ metadata.gz: 3b1630a683b93dd84c7e7687e2c52e49a43272dc81256654ebd51033cc4b0eff8b17669f43ee866e8ab7f3fc1a874e90ddd42e938e84ed0330fa7167a55eb963
7
+ data.tar.gz: 18bb1571676d2a33a4ba1ac48fe7780ffa1a02015ac1479f4057862478eb9f6837656a3dfa80838cf64bb131a73c84bbff6091a057a536743e9f8380e4ef9a86
data/.rvmrc CHANGED
@@ -1 +1,2 @@
1
- rvm use ruby-1.9.3-p125@pivot_table --create
1
+ # rvm use ruby-1.9.3-p448@pivot_table --create
2
+ rvm use ruby-2.0.0-p247@pivot_table --create
data/.travis.yml CHANGED
@@ -1,2 +1,3 @@
1
1
  rvm:
2
- - 1.9.3
2
+ - 1.9.3
3
+ - 2.0.0
data/Gemfile CHANGED
@@ -1,17 +1,10 @@
1
1
  source "http://rubygems.org"
2
-
3
- # Specify your gem's dependencies in pivot.gemspec
4
2
  gemspec
5
3
 
6
4
  gem 'rake'
7
5
 
8
6
  group :development, :test do
9
- #gem 'autotest'
10
- #gem 'autotest-growl'
11
- #gem 'autotest-notification'
12
- gem 'bundler'
13
- #gem 'launchy'
14
- #gem 'rcov'
15
7
  gem 'rspec'
16
- gem 'shoulda-matchers'
17
- end
8
+ gem 'growl'
9
+ gem 'guard-rspec'
10
+ end
data/Guardfile ADDED
@@ -0,0 +1,10 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ guard :rspec do
5
+ watch(%r{^spec/.+_spec\.rb$})
6
+ watch(%r{^lib/pivot_table.rb$}) { "spec" }
7
+ watch(%r{^lib/pivot_table/(.+)\.rb$}) { "spec" }
8
+ watch('spec/spec_helper.rb') { "spec" }
9
+ end
10
+
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2011 Ed James
1
+ Copyright (c) 2013 Ed James
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -17,4 +17,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
17
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
18
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
19
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,25 +1,20 @@
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)
2
- ===========
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)
2
+
3
3
 
4
4
  A handy tool for transforming a dataset into a spreadsheet-style pivot table.
5
5
 
6
- Why make this?
7
- --------------
6
+ ### Why make this?
8
7
 
9
8
  One of the most powerful and underrated features of spreadhseet packages is their ability to create pivot tables. I'm often asked
10
9
  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.
11
10
 
12
- Installation
13
- ------------
11
+ ### Installation
14
12
 
15
13
  Couldn't be easier...
16
14
 
17
15
  gem install pivot_table
18
16
 
19
- There are no dependencies and pivot *should* work on any version of Ruby.
20
-
21
- Usage
22
- -----
17
+ ### Usage
23
18
 
24
19
  At the very least, you will need to provide three things to create a pivot table...
25
20
 
@@ -43,7 +38,7 @@ Let's say you have a collection of Order objects that looks like this:
43
38
  Instantiate a new PivotTable::Grid object like this...
44
39
 
45
40
  grid = PivotTable::Grid.new do |g|
46
- g.source_data = data
41
+ g.source_data = data
47
42
  g.column_name = :quarter
48
43
  g.row_name = :city
49
44
  g.value_name = :sales
@@ -108,17 +103,12 @@ If you want to get the totals for rows, columns, or the entire grid, you can pas
108
103
  g.rows[1].total
109
104
  g.grand_total
110
105
 
111
- Still to come
112
- -------------
113
-
114
- PivotTable is still in the very early stages of development. As my personal needs for evolve, I'll update the gem with new functionality accordingly.
115
- Feel free to fork and/or suggest new features.
116
106
 
117
- Ruby 1.9 only...for now
107
+ ### Ruby Support
118
108
  ----------------
119
109
 
120
- Right now PivotTable only supports Ruby 1.9. If you need support for 1.8 please feel free to fork and merge. I will not however be adding
121
- support for 1.8.
110
+ * 1.9.3
111
+ * 2.0.0
122
112
 
123
113
  Contributing to PivotTable
124
114
  ---------------------
@@ -136,4 +126,4 @@ If you want to contribute:
136
126
  Copyright
137
127
  ---------
138
128
 
139
- Copyright (c) 2011 Ed James. See LICENSE for details.
129
+ Copyright (c) 2013 Ed James. See LICENSE for details.
data/lib/pivot_table.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  $: << File.dirname(__FILE__)
2
2
 
3
3
  require "pivot_table/grid"
4
+ require "pivot_table/cell_collection"
4
5
  require "pivot_table/column"
5
6
  require "pivot_table/row"
6
7
 
7
8
  module PivotTable
8
- VERSION = "0.1.3"
9
+ VERSION = "0.1.4"
9
10
  end
@@ -0,0 +1,21 @@
1
+ module PivotTable
2
+ module CellCollection
3
+
4
+ ACCESSORS = [:header, :data, :value_name]
5
+
6
+ ACCESSORS.each do |a|
7
+ self.send(:attr_accessor, a)
8
+ end
9
+
10
+ def initialize(options = {})
11
+ ACCESSORS.each do |a|
12
+ self.send("#{a}=", options[a]) if options.has_key?(a)
13
+ end
14
+ end
15
+
16
+ def total
17
+ data.inject(0) { |t, x| t + (x ? x.send(value_name) : 0) }
18
+ end
19
+
20
+ end
21
+ end
@@ -1,21 +1,5 @@
1
1
  module PivotTable
2
2
  class Column
3
-
4
- ACCESSORS = [:header, :data, :value_name]
5
-
6
- ACCESSORS.each do |a|
7
- self.send(:attr_accessor, a)
8
- end
9
-
10
- def initialize(options = {})
11
- ACCESSORS.each do |a|
12
- self.send("#{a}=", options[a]) if options.has_key?(a)
13
- end
14
- end
15
-
16
- def total
17
- data.inject(0){|t,x| t + (x ? x.send(value_name) : 0)}
18
- end
19
-
3
+ include CellCollection
20
4
  end
21
5
  end
@@ -18,14 +18,22 @@ module PivotTable
18
18
  def build_rows
19
19
  @rows = []
20
20
  @data_grid.each_with_index do |data, index|
21
- @rows << Row.new(:header => row_headers[index], :data => data, :value_name => value_name)
21
+ @rows << Row.new(
22
+ :header => row_headers[index],
23
+ :data => data,
24
+ :value_name => value_name
25
+ )
22
26
  end
23
27
  end
24
28
 
25
29
  def build_columns
26
30
  @columns = []
27
31
  @data_grid.transpose.each_with_index do |data, index|
28
- @columns << Column.new(:header => column_headers[index], :data => data, :value_name => value_name)
32
+ @columns << Column.new(
33
+ :header => column_headers[index],
34
+ :data => data,
35
+ :value_name => value_name
36
+ )
29
37
  end
30
38
  end
31
39
 
@@ -38,15 +46,15 @@ module PivotTable
38
46
  end
39
47
 
40
48
  def column_totals
41
- columns.map{|c| c.total}
49
+ columns.map { |c| c.total }
42
50
  end
43
51
 
44
52
  def row_totals
45
- rows.map{|r| r.total}
53
+ rows.map { |r| r.total }
46
54
  end
47
55
 
48
56
  def grand_total
49
- column_totals.inject(0){|t,x| t + x}
57
+ column_totals.inject(0) { |t, x| t + x }
50
58
  end
51
59
 
52
60
  def prepare_grid
@@ -70,7 +78,8 @@ module PivotTable
70
78
  end
71
79
 
72
80
  private
73
- def headers method
81
+
82
+ def headers(method)
74
83
  @source_data.collect { |c| c.send method }.uniq.sort
75
84
  end
76
85
 
@@ -1,21 +1,5 @@
1
1
  module PivotTable
2
2
  class Row
3
-
4
- ACCESSORS = [:header, :data, :value_name]
5
-
6
- ACCESSORS.each do |a|
7
- self.send(:attr_accessor, a)
8
- end
9
-
10
- def initialize(options = {})
11
- ACCESSORS.each do |a|
12
- self.send("#{a}=", options[a]) if options.has_key?(a)
13
- end
14
- end
15
-
16
- def total
17
- data.inject(0){|t,x| t + (x ? x.send(value_name) : 0)}
18
- end
19
-
3
+ include CellCollection
20
4
  end
21
5
  end
data/pivot_table.gemspec CHANGED
@@ -15,9 +15,13 @@ Gem::Specification.new do |s|
15
15
  s.required_ruby_version = '>= 1.9'
16
16
 
17
17
  s.rubyforge_project = "pivot_table"
18
- s.rubygems_version = ">= 1.6.1"
19
- s.files = `git ls-files`.split("\n")
20
- s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
21
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
- s.require_paths = ["lib"]
18
+ s.rubygems_version = ">= 1.6.1"
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.files = `git ls-files`.split("\n")
21
+ s.test_files = `git ls-files -- {spec,features}/*`.split("\n")
22
+ s.require_paths = ["lib"]
23
+
24
+ s.add_development_dependency "rspec", "~> 2.14"
25
+ s.add_development_dependency "growl", "~> 1.0"
26
+ s.add_development_dependency "guard-rspec", "~> 4.0"
23
27
  end
@@ -4,19 +4,7 @@ module PivotTable
4
4
  describe Column do
5
5
 
6
6
  let(:klass) { Column }
7
-
8
- before { @instance = klass.new }
9
-
10
- it { should respond_to :header }
11
- it { should respond_to :data }
12
- it { should respond_to :total }
13
-
14
- context 'initialize with hash' do
15
- subject { klass.new(header: 'header', data: 'data', total: 'total')}
16
-
17
- its(:header) { should == 'header' }
18
- its(:data) { should == 'data' }
19
- end
7
+ it_should_behave_like "a cell collection"
20
8
 
21
9
  end
22
10
  end
@@ -4,19 +4,7 @@ module PivotTable
4
4
  describe Row do
5
5
 
6
6
  let(:klass) { Row }
7
-
8
- before { @instance = klass.new }
9
-
10
- it { should respond_to :header }
11
- it { should respond_to :data }
12
- it { should respond_to :total }
13
-
14
- context 'initialize with hash' do
15
- subject { klass.new(header: 'header', data: 'data')}
16
-
17
- its(:header) { should == 'header' }
18
- its(:data) { should == 'data' }
19
- end
7
+ it_should_behave_like "a cell collection"
20
8
 
21
9
  end
22
10
  end
data/spec/spec_helper.rb CHANGED
@@ -7,8 +7,8 @@ require 'ostruct'
7
7
 
8
8
  # Requires supporting files with custom matchers and macros, etc,
9
9
  # in ./support/ and its subdirectories.
10
- Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+ Dir["./spec/support/**/*.rb"].each {|f| require f}
11
11
 
12
12
  RSpec.configure do |config|
13
13
 
14
- end
14
+ end
@@ -0,0 +1,20 @@
1
+ shared_examples "a cell collection" do
2
+
3
+ it { should respond_to :header }
4
+ it { should respond_to :data }
5
+ it { should respond_to :value_name }
6
+ it { should respond_to :total }
7
+
8
+ context 'initialize with hash' do
9
+ subject { klass.new(attrs) }
10
+
11
+ let(:attrs) do
12
+ { header: 'header', data: 'data', value_name: "value_name" }
13
+ end
14
+
15
+ its(:header) { should == attrs[:header] }
16
+ its(:data) { should == attrs[:data] }
17
+ its(:value_name) { should == attrs[:value_name] }
18
+ end
19
+
20
+ end
metadata CHANGED
@@ -1,19 +1,59 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pivot_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
5
- prerelease:
4
+ version: 0.1.4
6
5
  platform: ruby
7
6
  authors:
8
7
  - Ed James
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-10-14 00:00:00.000000000 Z
13
- dependencies: []
11
+ date: 2013-10-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '2.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '2.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: growl
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: guard-rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '4.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '4.0'
14
55
  description: Transform an ActiveRecord-ish data set into a pivot table of objects
15
- email: !binary |-
16
- ZWQuamFtZXMuZW1haWxAZ21haWwuY29t
56
+ email: ed.james.email@gmail.com
17
57
  executables: []
18
58
  extensions: []
19
59
  extra_rdoc_files: []
@@ -22,12 +62,13 @@ files:
22
62
  - .rspec
23
63
  - .rvmrc
24
64
  - .travis.yml
25
- - CHANGELOG.md
26
65
  - Gemfile
66
+ - Guardfile
27
67
  - LICENSE
28
68
  - README.md
29
69
  - Rakefile
30
70
  - lib/pivot_table.rb
71
+ - lib/pivot_table/cell_collection.rb
31
72
  - lib/pivot_table/column.rb
32
73
  - lib/pivot_table/grid.rb
33
74
  - lib/pivot_table/row.rb
@@ -36,32 +77,33 @@ files:
36
77
  - spec/pivot_table/grid_spec.rb
37
78
  - spec/pivot_table/row_spec.rb
38
79
  - spec/spec_helper.rb
80
+ - spec/support/shared_examples.rb
39
81
  homepage: https://github.com/edjames/pivot_table
40
82
  licenses: []
83
+ metadata: {}
41
84
  post_install_message:
42
85
  rdoc_options: []
43
86
  require_paths:
44
87
  - lib
45
88
  required_ruby_version: !ruby/object:Gem::Requirement
46
- none: false
47
89
  requirements:
48
- - - ! '>='
90
+ - - '>='
49
91
  - !ruby/object:Gem::Version
50
92
  version: '1.9'
51
93
  required_rubygems_version: !ruby/object:Gem::Requirement
52
- none: false
53
94
  requirements:
54
- - - ! '>='
95
+ - - '>='
55
96
  - !ruby/object:Gem::Version
56
97
  version: '0'
57
98
  requirements: []
58
99
  rubyforge_project: pivot_table
59
- rubygems_version: 1.8.15
100
+ rubygems_version: 2.0.3
60
101
  signing_key:
61
- specification_version: 3
62
- summary: pivot_table-0.1.3
102
+ specification_version: 4
103
+ summary: pivot_table-0.1.4
63
104
  test_files:
64
105
  - spec/pivot_table/column_spec.rb
65
106
  - spec/pivot_table/grid_spec.rb
66
107
  - spec/pivot_table/row_spec.rb
67
108
  - spec/spec_helper.rb
109
+ - spec/support/shared_examples.rb
data/CHANGELOG.md DELETED
@@ -1,17 +0,0 @@
1
- Changelog
2
- =========
3
- 0.1.2
4
- ---
5
- Removed testing gems and updated Ruby version to 1.9.3
6
-
7
- 0.0.3
8
- ---
9
- Renamed gem to pivot_table
10
-
11
- 0.0.2
12
- ---
13
- Major refactoring to allow unbalanced dataset to be pivoted.
14
-
15
- 0.0.1
16
- ---
17
- Initial release.