pivot_table 0.2.0 → 0.3.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 +4 -4
- data/.rspec +4 -2
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +1 -0
- data/Gemfile +2 -1
- data/Guardfile +10 -4
- data/README.md +31 -26
- data/lib/pivot_table.rb +1 -1
- data/lib/pivot_table/cell_collection.rb +9 -1
- data/lib/pivot_table/column.rb +4 -0
- data/lib/pivot_table/grid.rb +6 -4
- data/lib/pivot_table/row.rb +4 -0
- data/pivot_table.gemspec +3 -3
- data/spec/pivot_table/configuration_spec.rb +3 -3
- data/spec/pivot_table/grid_spec.rb +6 -6
- data/spec/pivot_table_helper.rb +15 -0
- data/spec/spec_helper.rb +84 -11
- data/spec/support/shared_examples_for_a_cell_collection_.rb +24 -12
- data/spec/support/shared_examples_for_a_collection_of_columns.rb +15 -11
- data/spec/support/shared_examples_for_a_collection_of_rows.rb +12 -8
- data/spec/support/shared_examples_for_a_data_grid.rb +5 -5
- metadata +23 -20
- data/.rvmrc +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 358c82d5e3a1a349a27b0a35e34c2a2b764fc9f5
|
4
|
+
data.tar.gz: 725ff8d73693f14eee2c0d868942f8e6c58f6e1a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c09f55135466324aec7bcd16006dc30a7f6e2b3421bb0d994be06d22ad382b0c91f55f8dda9ff94b37d5c37096cd524562b061ca4603973cec004393c481848
|
7
|
+
data.tar.gz: 7a976c7c17833be45c8a3a34bfbbc9ff4d8a240d11582b2c57fa4b8406c364b9c13a33f7295251529738fb8e4e89eedb5f4e004fc3a0ab43f31e61512b259e34
|
data/.rspec
CHANGED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pivot_table
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.2
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Guardfile
CHANGED
@@ -1,8 +1,14 @@
|
|
1
|
-
#
|
2
|
-
#
|
3
|
-
|
4
|
-
|
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
|
5
10
|
watch(%r{^spec/.+_spec\.rb$})
|
11
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
6
12
|
watch(%r{^lib/pivot_table.rb$}) { "spec" }
|
7
13
|
watch(%r{^lib/pivot_table/(.+)\.rb$}) { "spec" }
|
8
14
|
watch('spec/spec_helper.rb') { "spec" }
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Pivot Table [](http://travis-ci.org/edjames/pivot_table) [](https://codeclimate.com/github/edjames/pivot_table) [](https://gemnasium.com/edjames/pivot_table)
|
1
|
+
# Pivot Table [](http://travis-ci.org/edjames/pivot_table) [](https://codeclimate.com/github/edjames/pivot_table) [](https://gemnasium.com/edjames/pivot_table) [](http://badge.fury.io/rb/pivot_table)
|
2
2
|
|
3
3
|
A handy tool for transforming a dataset into a spreadsheet-style pivot table.
|
4
4
|
|
@@ -23,20 +23,20 @@ At the very least, you will need to provide three things to create a pivot table
|
|
23
23
|
|
24
24
|
Let's say you have a collection of Order objects that looks like this:
|
25
25
|
|
26
|
-
obj_1 = Order.new(:
|
27
|
-
obj_2 = Order.new(:
|
28
|
-
obj_3 = Order.new(:
|
29
|
-
obj_4 = Order.new(:
|
30
|
-
obj_5 = Order.new(:
|
31
|
-
obj_6 = Order.new(:
|
32
|
-
obj_7 = Order.new(:
|
33
|
-
obj_8 = Order.new(:
|
26
|
+
obj_1 = Order.new(city: 'London', quarter: 'Q1')
|
27
|
+
obj_2 = Order.new(city: 'London', quarter: 'Q2')
|
28
|
+
obj_3 = Order.new(city: 'London', quarter: 'Q3')
|
29
|
+
obj_4 = Order.new(city: 'London', quarter: 'Q4')
|
30
|
+
obj_5 = Order.new(city: 'New York', quarter: 'Q1')
|
31
|
+
obj_6 = Order.new(city: 'New York', quarter: 'Q2')
|
32
|
+
obj_7 = Order.new(city: 'New York', quarter: 'Q3')
|
33
|
+
obj_8 = Order.new(city: 'New York', quarter: 'Q4')
|
34
34
|
|
35
35
|
data = [ obj_1, obj_2, obj_3, obj_4, obj_5, obj_6, obj_7, obj_8 ]
|
36
36
|
|
37
37
|
Instantiate a new PivotTable::Grid object like this...
|
38
38
|
|
39
|
-
|
39
|
+
g = PivotTable::Grid.new do |g|
|
40
40
|
g.source_data = data
|
41
41
|
g.column_name = :quarter
|
42
42
|
g.row_name = :city
|
@@ -65,26 +65,32 @@ Then you have the following aspects of the pivot table grid available to you...
|
|
65
65
|
g.row_headers => ['London', 'New York']
|
66
66
|
g.rows.length => 2
|
67
67
|
|
68
|
-
g.rows[0].header
|
69
|
-
g.rows[0].data
|
68
|
+
g.rows[0].header => 'London'
|
69
|
+
g.rows[0].data => [obj_1, obj_2, obj_3, obj_4]
|
70
|
+
g.rows[0].column_data('Q2') => obj_2
|
70
71
|
|
71
|
-
g.rows[1].header
|
72
|
-
g.rows[1].data
|
72
|
+
g.rows[1].header => 'New York'
|
73
|
+
g.rows[1].data => [obj_5, obj_6, obj_7, obj_8]
|
74
|
+
g.rows[1].column_data('Q2') => obj_6
|
73
75
|
|
74
76
|
g.column_headers => ['Q1', 'Q2', 'Q3', 'Q4']
|
75
77
|
g.columns.length => 4
|
76
78
|
|
77
|
-
g.columns[0].header
|
78
|
-
g.columns[0].data
|
79
|
+
g.columns[0].header => 'Q1'
|
80
|
+
g.columns[0].data => [obj_1, obj_5]
|
81
|
+
g.columns[0].row_data('London') => obj_1
|
79
82
|
|
80
|
-
g.columns[1].header
|
81
|
-
g.columns[1].data
|
83
|
+
g.columns[1].header => 'Q2'
|
84
|
+
g.columns[1].data => [obj_2, obj_6]
|
85
|
+
g.columns[1].row_data('London') => obj_2
|
82
86
|
|
83
|
-
g.columns[2].header
|
84
|
-
g.columns[2].data
|
87
|
+
g.columns[2].header => 'Q3'
|
88
|
+
g.columns[2].data => [obj_3, obj_7]
|
89
|
+
g.columns[2].row_data('London') => obj_3
|
85
90
|
|
86
|
-
g.columns[3].header
|
87
|
-
g.columns[3].data
|
91
|
+
g.columns[3].header => 'Q4'
|
92
|
+
g.columns[3].data => [obj_4, obj_8]
|
93
|
+
g.columns[3].row_data('London') => obj_4
|
88
94
|
|
89
95
|
The API should give you a lot of flexibility with regards to rendering this information in your views.
|
90
96
|
E.g. The rows and columns collections make it very easy to produce horizontal, vertical and overall total values.
|
@@ -106,7 +112,7 @@ If you want to get the totals for rows, columns, or the entire grid, you can pas
|
|
106
112
|
|
107
113
|
You can also provide additional configuration options when instantiating your Grid. Options are provided as a hash e.g.
|
108
114
|
|
109
|
-
|
115
|
+
g = PivotTable::Grid.new(:sort => true) do |g|
|
110
116
|
g.source_data = data
|
111
117
|
g.column_name = :quarter
|
112
118
|
g.row_name = :city
|
@@ -117,7 +123,7 @@ Here are the available configuration options:
|
|
117
123
|
|
118
124
|
###### 1. Sort
|
119
125
|
|
120
|
-
**Usage:**
|
126
|
+
**Usage:** `sort: false`
|
121
127
|
|
122
128
|
**Default:** `true`
|
123
129
|
|
@@ -127,8 +133,7 @@ This option will automatically sort your data alphabetically based on your colum
|
|
127
133
|
### Ruby Support
|
128
134
|
|
129
135
|
* 1.9.3
|
130
|
-
* 2.
|
131
|
-
* 2.1.0
|
136
|
+
* 2.x
|
132
137
|
|
133
138
|
### Contributing to PivotTable
|
134
139
|
|
data/lib/pivot_table.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module PivotTable
|
2
2
|
module CellCollection
|
3
3
|
|
4
|
-
ACCESSORS = [:header, :data, :value_name]
|
4
|
+
ACCESSORS = [:header, :data, :value_name, :orthogonal_headers]
|
5
5
|
|
6
6
|
ACCESSORS.each do |a|
|
7
7
|
self.send(:attr_accessor, a)
|
@@ -17,5 +17,13 @@ module PivotTable
|
|
17
17
|
data.inject(0) { |t, x| t + (x ? x.send(value_name) : 0) }
|
18
18
|
end
|
19
19
|
|
20
|
+
private
|
21
|
+
|
22
|
+
def find_data by_header_name
|
23
|
+
data[
|
24
|
+
orthogonal_headers.find_index{|header| by_header_name.to_s == header.to_s}
|
25
|
+
] rescue nil
|
26
|
+
end
|
27
|
+
|
20
28
|
end
|
21
29
|
end
|
data/lib/pivot_table/column.rb
CHANGED
data/lib/pivot_table/grid.rb
CHANGED
@@ -26,7 +26,8 @@ module PivotTable
|
|
26
26
|
@rows << Row.new(
|
27
27
|
:header => row_headers[index],
|
28
28
|
:data => data,
|
29
|
-
:value_name => value_name
|
29
|
+
:value_name => value_name,
|
30
|
+
:orthogonal_headers => column_headers
|
30
31
|
)
|
31
32
|
end
|
32
33
|
end
|
@@ -35,9 +36,10 @@ module PivotTable
|
|
35
36
|
@columns = []
|
36
37
|
@data_grid.transpose.each_with_index do |data, index|
|
37
38
|
@columns << Column.new(
|
38
|
-
:header
|
39
|
-
:data
|
40
|
-
:value_name
|
39
|
+
:header => column_headers[index],
|
40
|
+
:data => data,
|
41
|
+
:value_name => value_name,
|
42
|
+
:orthogonal_headers => row_headers
|
41
43
|
)
|
42
44
|
end
|
43
45
|
end
|
data/lib/pivot_table/row.rb
CHANGED
data/pivot_table.gemspec
CHANGED
@@ -15,13 +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 = "
|
18
|
+
s.rubygems_version = "~> 2.2"
|
19
19
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
20
|
s.files = `git ls-files`.split("\n")
|
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", "~>
|
24
|
+
s.add_development_dependency "rspec", "~> 3.1"
|
25
25
|
s.add_development_dependency "growl", "~> 1.0"
|
26
|
-
s.add_development_dependency "guard-rspec", "~> 4.
|
26
|
+
s.add_development_dependency "guard-rspec", "~> 4.3"
|
27
27
|
end
|
@@ -7,11 +7,11 @@ module PivotTable
|
|
7
7
|
|
8
8
|
let(:opts) { { :sort => true, :other_setting => 'on' } }
|
9
9
|
|
10
|
-
its(:sort) {
|
11
|
-
its(:other_setting) {
|
10
|
+
its(:sort) { is_expected.to eq true }
|
11
|
+
its(:other_setting) { is_expected.to eq 'on' }
|
12
12
|
|
13
13
|
context 'when setting does not exist' do
|
14
|
-
its(:i_do_not_exist) {
|
14
|
+
its(:i_do_not_exist) { is_expected.to be_nil }
|
15
15
|
end
|
16
16
|
|
17
17
|
end
|
@@ -4,12 +4,12 @@ module PivotTable
|
|
4
4
|
describe Grid do
|
5
5
|
|
6
6
|
context 'accessors' do
|
7
|
-
it {
|
8
|
-
it {
|
9
|
-
it {
|
10
|
-
it {
|
11
|
-
it {
|
12
|
-
it {
|
7
|
+
it { is_expected.to respond_to :source_data }
|
8
|
+
it { is_expected.to respond_to :row_name }
|
9
|
+
it { is_expected.to respond_to :column_name }
|
10
|
+
it { is_expected.to respond_to :columns }
|
11
|
+
it { is_expected.to respond_to :rows }
|
12
|
+
it { is_expected.to respond_to :grand_total }
|
13
13
|
end
|
14
14
|
|
15
15
|
let(:d1) { build_data_object(1, 'r1', 'c1') }
|
@@ -0,0 +1,15 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rubygems'
|
4
|
+
require 'rspec'
|
5
|
+
require 'rspec/its'
|
6
|
+
require 'pivot_table'
|
7
|
+
require 'ostruct'
|
8
|
+
|
9
|
+
# Requires supporting files with custom matchers and macros, etc,
|
10
|
+
# in ./support/ and its subdirectories.
|
11
|
+
Dir["./spec/support/**/*.rb"].each {|f| require f}
|
12
|
+
|
13
|
+
RSpec.configure do |config|
|
14
|
+
config.include Helpers
|
15
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,16 +1,89 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
|
6
|
-
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause this
|
4
|
+
# file to always be loaded, without a need to explicitly require it in any files.
|
5
|
+
#
|
6
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
7
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
8
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
9
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
10
|
+
# a separate helper file that requires the additional dependencies and performs
|
11
|
+
# the additional setup, and require it from the spec files that actually need it.
|
12
|
+
#
|
13
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
14
|
+
# users commonly want.
|
15
|
+
#
|
16
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
17
|
+
RSpec.configure do |config|
|
18
|
+
# rspec-expectations config goes here. You can use an alternate
|
19
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
20
|
+
# assertions if you prefer.
|
21
|
+
config.expect_with :rspec do |expectations|
|
22
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
23
|
+
# and `failure_message` of custom matchers include text for helper methods
|
24
|
+
# defined using `chain`, e.g.:
|
25
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
26
|
+
# # => "be bigger than 2 and smaller than 4"
|
27
|
+
# ...rather than:
|
28
|
+
# # => "be bigger than 2"
|
29
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
30
|
+
end
|
7
31
|
|
8
|
-
#
|
9
|
-
#
|
10
|
-
|
32
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
33
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
34
|
+
config.mock_with :rspec do |mocks|
|
35
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
36
|
+
# a real object. This is generally recommended, and will default to
|
37
|
+
# `true` in RSpec 4.
|
38
|
+
mocks.verify_partial_doubles = true
|
39
|
+
end
|
11
40
|
|
12
|
-
|
41
|
+
# The settings below are suggested to provide a good initial experience
|
42
|
+
# with RSpec, but feel free to customize to your heart's content.
|
43
|
+
=begin
|
44
|
+
# These two settings work together to allow you to limit a spec run
|
45
|
+
# to individual examples or groups you care about by tagging them with
|
46
|
+
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
47
|
+
# get run.
|
48
|
+
config.filter_run :focus
|
49
|
+
config.run_all_when_everything_filtered = true
|
50
|
+
|
51
|
+
# Limits the available syntax to the non-monkey patched syntax that is recommended.
|
52
|
+
# For more details, see:
|
53
|
+
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
54
|
+
# - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
55
|
+
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
56
|
+
config.disable_monkey_patching!
|
57
|
+
|
58
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
59
|
+
# be too noisy due to issues in dependencies.
|
60
|
+
config.warnings = true
|
61
|
+
|
62
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
63
|
+
# file, and it's useful to allow more verbose output when running an
|
64
|
+
# individual spec file.
|
65
|
+
if config.files_to_run.one?
|
66
|
+
# Use the documentation formatter for detailed output,
|
67
|
+
# unless a formatter has already been configured
|
68
|
+
# (e.g. via a command-line flag).
|
69
|
+
config.default_formatter = 'doc'
|
70
|
+
end
|
71
|
+
|
72
|
+
# Print the 10 slowest examples and example groups at the
|
73
|
+
# end of the spec run, to help surface which specs are running
|
74
|
+
# particularly slow.
|
75
|
+
config.profile_examples = 10
|
13
76
|
|
14
|
-
|
77
|
+
# Run specs in random order to surface order dependencies. If you find an
|
78
|
+
# order dependency and want to debug it, you can fix the order by providing
|
79
|
+
# the seed, which is printed after each run.
|
80
|
+
# --seed 1234
|
81
|
+
config.order = :random
|
15
82
|
|
83
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
84
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
85
|
+
# test failures related to randomization by passing the same `--seed` value
|
86
|
+
# as the one that triggered the failure.
|
87
|
+
Kernel.srand config.seed
|
88
|
+
=end
|
16
89
|
end
|
@@ -1,18 +1,30 @@
|
|
1
1
|
shared_examples "a cell collection" do
|
2
|
-
it {
|
3
|
-
it {
|
4
|
-
it {
|
5
|
-
it {
|
2
|
+
it { is_expected.to respond_to :header }
|
3
|
+
it { is_expected.to respond_to :data }
|
4
|
+
it { is_expected.to respond_to :value_name }
|
5
|
+
it { is_expected.to respond_to :total }
|
6
|
+
it { is_expected.to respond_to :orthogonal_headers }
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
subject(:instance) { klass.new(attrs) }
|
9
|
+
|
10
|
+
let(:data) do
|
11
|
+
{ a: 1, b: 2 }
|
12
|
+
end
|
9
13
|
|
10
|
-
|
11
|
-
|
12
|
-
|
14
|
+
let(:attrs) do
|
15
|
+
{ header: 'header', data: data.values, value_name: "value_name", orthogonal_headers: data.keys }
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'initialize with hash' do
|
19
|
+
its(:header) { is_expected.to eq attrs[:header] }
|
20
|
+
its(:data) { is_expected.to eq attrs[:data] }
|
21
|
+
its(:value_name) { is_expected.to eq attrs[:value_name] }
|
22
|
+
its(:orthogonal_headers) { is_expected.to eq attrs[:orthogonal_headers] }
|
23
|
+
end
|
13
24
|
|
14
|
-
|
15
|
-
|
16
|
-
|
25
|
+
it "finds data by orthogonal header name" do
|
26
|
+
expect(instance.send :find_data, :a).to equal(data[:a])
|
27
|
+
expect(instance.send :find_data, :b).to equal(data[:b])
|
28
|
+
expect(instance.send :find_data, :c).to be_nil
|
17
29
|
end
|
18
30
|
end
|
@@ -1,30 +1,34 @@
|
|
1
1
|
shared_examples 'a collection of columns' do
|
2
2
|
let(:build_result) { instance.build }
|
3
|
-
|
3
|
+
|
4
|
+
context 'column count' do
|
5
|
+
subject { build_result.columns.length }
|
6
|
+
it { is_expected.to eq 3 }
|
7
|
+
end
|
4
8
|
|
5
9
|
context 'column headers' do
|
6
10
|
subject { build_result.column_headers }
|
7
|
-
it {
|
11
|
+
it { is_expected.to eq column_headers }
|
8
12
|
end
|
9
13
|
|
10
14
|
context '1st column' do
|
11
15
|
subject { build_result.columns[0] }
|
12
|
-
its(:header) {
|
13
|
-
its(:data) {
|
14
|
-
its(:total) {
|
16
|
+
its(:header) { is_expected.to eq column_headers[0] }
|
17
|
+
its(:data) { is_expected.to eq column_0 }
|
18
|
+
its(:total) { is_expected.to eq column_totals[0] }
|
15
19
|
end
|
16
20
|
|
17
21
|
context '2nd column' do
|
18
22
|
subject { build_result.columns[1] }
|
19
|
-
its(:header) {
|
20
|
-
its(:data) {
|
21
|
-
its(:total) {
|
23
|
+
its(:header) { is_expected.to eq column_headers[1] }
|
24
|
+
its(:data) { is_expected.to eq column_1 }
|
25
|
+
its(:total) { is_expected.to eq column_totals[1] }
|
22
26
|
end
|
23
27
|
|
24
28
|
context '3rd column' do
|
25
29
|
subject { build_result.columns[2] }
|
26
|
-
its(:header) {
|
27
|
-
its(:data) {
|
28
|
-
its(:total) {
|
30
|
+
its(:header) { is_expected.to eq column_headers[2] }
|
31
|
+
its(:data) { is_expected.to eq column_2 }
|
32
|
+
its(:total) { is_expected.to eq column_totals[2] }
|
29
33
|
end
|
30
34
|
end
|
@@ -1,23 +1,27 @@
|
|
1
1
|
shared_examples 'a collection of rows' do
|
2
2
|
let(:build_result) { instance.build }
|
3
|
-
|
3
|
+
|
4
|
+
context 'row count' do
|
5
|
+
subject { build_result.rows.length }
|
6
|
+
it { is_expected.to eq 2 }
|
7
|
+
end
|
4
8
|
|
5
9
|
context 'row headers' do
|
6
10
|
subject { build_result.row_headers }
|
7
|
-
it {
|
11
|
+
it { is_expected.to eq row_headers }
|
8
12
|
end
|
9
13
|
|
10
14
|
context '1st row' do
|
11
15
|
subject { build_result.rows[0] }
|
12
|
-
its(:header) {
|
13
|
-
its(:data) {
|
14
|
-
its(:total) {
|
16
|
+
its(:header) { is_expected.to eq row_headers[0] }
|
17
|
+
its(:data) { is_expected.to eq row_0 }
|
18
|
+
its(:total) { is_expected.to eq row_totals[0] }
|
15
19
|
end
|
16
20
|
|
17
21
|
context '2nd row' do
|
18
22
|
subject { build_result.rows[1] }
|
19
|
-
its(:header) {
|
20
|
-
its(:data) {
|
21
|
-
its(:total) {
|
23
|
+
its(:header) { is_expected.to eq row_headers[1] }
|
24
|
+
its(:data) { is_expected.to eq row_1 }
|
25
|
+
its(:total) { is_expected.to eq row_totals[1] }
|
22
26
|
end
|
23
27
|
end
|
@@ -3,18 +3,18 @@ shared_examples 'a data grid' do
|
|
3
3
|
|
4
4
|
context 'preparing the grid' do
|
5
5
|
subject { build_result.prepare_grid }
|
6
|
-
it {
|
6
|
+
it { is_expected.to eq [[nil, nil, nil], [nil, nil, nil]] }
|
7
7
|
end
|
8
8
|
|
9
9
|
context 'populating the grid' do
|
10
10
|
subject { build_result.data_grid }
|
11
|
-
it {
|
11
|
+
it { is_expected.to eq [row_0, row_1] }
|
12
12
|
end
|
13
13
|
|
14
14
|
context 'totals' do
|
15
15
|
subject { build_result }
|
16
|
-
its(:column_totals) {
|
17
|
-
its(:row_totals) {
|
18
|
-
its(:grand_total) {
|
16
|
+
its(:column_totals) { is_expected.to eq column_totals }
|
17
|
+
its(:row_totals) { is_expected.to eq row_totals }
|
18
|
+
its(:grand_total) { is_expected.to eq grand_total }
|
19
19
|
end
|
20
20
|
end
|
metadata
CHANGED
@@ -1,67 +1,68 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pivot_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.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: 2014-
|
11
|
+
date: 2014-10-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '3.1'
|
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: '
|
26
|
+
version: '3.1'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: growl
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: guard-rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - ~>
|
45
|
+
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '4.
|
47
|
+
version: '4.3'
|
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.
|
54
|
+
version: '4.3'
|
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: []
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
-
- .gitignore
|
62
|
-
- .rspec
|
63
|
-
- .
|
64
|
-
- .
|
61
|
+
- ".gitignore"
|
62
|
+
- ".rspec"
|
63
|
+
- ".ruby-gemset"
|
64
|
+
- ".ruby-version"
|
65
|
+
- ".travis.yml"
|
65
66
|
- Gemfile
|
66
67
|
- Guardfile
|
67
68
|
- LICENSE
|
@@ -78,6 +79,7 @@ files:
|
|
78
79
|
- spec/pivot_table/configuration_spec.rb
|
79
80
|
- spec/pivot_table/grid_spec.rb
|
80
81
|
- spec/pivot_table/row_spec.rb
|
82
|
+
- spec/pivot_table_helper.rb
|
81
83
|
- spec/spec_helper.rb
|
82
84
|
- spec/support/helpers.rb
|
83
85
|
- spec/support/shared_examples_for_a_cell_collection_.rb
|
@@ -93,25 +95,26 @@ require_paths:
|
|
93
95
|
- lib
|
94
96
|
required_ruby_version: !ruby/object:Gem::Requirement
|
95
97
|
requirements:
|
96
|
-
- -
|
98
|
+
- - ">="
|
97
99
|
- !ruby/object:Gem::Version
|
98
100
|
version: '1.9'
|
99
101
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
102
|
requirements:
|
101
|
-
- -
|
103
|
+
- - ">="
|
102
104
|
- !ruby/object:Gem::Version
|
103
105
|
version: '0'
|
104
106
|
requirements: []
|
105
107
|
rubyforge_project: pivot_table
|
106
|
-
rubygems_version: 2.
|
108
|
+
rubygems_version: 2.2.2
|
107
109
|
signing_key:
|
108
110
|
specification_version: 4
|
109
|
-
summary: pivot_table-0.
|
111
|
+
summary: pivot_table-0.3.0
|
110
112
|
test_files:
|
111
113
|
- spec/pivot_table/column_spec.rb
|
112
114
|
- spec/pivot_table/configuration_spec.rb
|
113
115
|
- spec/pivot_table/grid_spec.rb
|
114
116
|
- spec/pivot_table/row_spec.rb
|
117
|
+
- spec/pivot_table_helper.rb
|
115
118
|
- spec/spec_helper.rb
|
116
119
|
- spec/support/helpers.rb
|
117
120
|
- spec/support/shared_examples_for_a_cell_collection_.rb
|
data/.rvmrc
DELETED