README.md in pivot_table-0.1.1 vs README.md in pivot_table-0.1.3
- old
+ new
@@ -1,6 +1,6 @@
-Pivot Table [![Build Status](https://secure.travis-ci.org/edjames/pivot_table.png)](http://travis-ci.org/edjames/pivot_table)
+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)
===========
A handy tool for transforming a dataset into a spreadsheet-style pivot table.
Why make this?
@@ -14,16 +14,16 @@
Couldn't be easier...
gem install pivot_table
-There are no dependencies and pivot will work on any version of Ruby.
+There are no dependencies and pivot *should* work on any version of Ruby.
Usage
-----
-At the very least, you will need to provide four things to create a pivot table...
+At the very least, you will need to provide three things to create a pivot table...
* a dataset (this doesn't necessarily have to be an ActiveRecord dataset, but it should at least behave like ActiveRecord e.g. OpenStruct)
* the method to be used as column names
* the method to be used as row names
@@ -41,16 +41,20 @@
data = [ obj_1, obj_2, obj_3, obj_4, obj_5, obj_6, obj_7, obj_8 ]
Instantiate a new PivotTable::Grid object like this...
grid = PivotTable::Grid.new do |g|
- g.sourcedata = data
+ g.source_data = data
g.column_name = :quarter
g.row_name = :city
+ g.value_name = :sales
end
+The `value_name` parameter is only required if you want to access totals;
+the others are required.
+
All you have to do now is build the grid...
g.build
This will give you a logical grid (represented by an two-dimensional array) which can be likened to this table:
@@ -91,10 +95,21 @@
The API should give you a lot of flexibility with regards to rendering this information in your views.
E.g. The rows and columns collections make it very easy to produce horizontal, vertical and overall total values.
Ah, that's better.
+If you want to get the totals for rows, columns, or the entire grid, you can pass a `value_name` as shown above, and then query the Grid like this:
+
+ g.column_totals
+ g.columns[0].total
+ g.columns[1].total
+ g.columns[2].total
+ g.row_totals
+ g.rows[0].total
+ g.rows[1].total
+ g.grand_total
+
Still to come
-------------
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.
Feel free to fork and/or suggest new features.
@@ -119,6 +134,6 @@
* Please try not to mess with the Rakefile, version, or history.
Copyright
---------
-Copyright (c) 2011 Ed James. See LICENSE for details.
\ No newline at end of file
+Copyright (c) 2011 Ed James. See LICENSE for details.