Skip to content
Browse files

Version: 0.0.6. Summary functionality works with sparse matrix.

  • Loading branch information...
1 parent 2457bf9 commit 0df55aa7d9007166df9d76a6005830a250479281 @MitinPavel MitinPavel committed Feb 20, 2012
Showing with 24 additions and 2 deletions.
  1. +10 −1 lib/tabloid/data.rb
  2. +1 −1 lib/tabloid/version.rb
  3. +13 −0 spec/lib/tabloid/data_spec.rb
View
11 lib/tabloid/data.rb
@@ -144,7 +144,16 @@ def visible_column_count
end
def sum
- proc(&:+)
+ proc do |accumulator, entry|
+ if accumulator && entry
+ accumulator += entry
+ accumulator
+ elsif entry
+ entry
+ else
+ accumulator
+ end
+ end
end
def summary_present?
View
2 lib/tabloid/version.rb
@@ -1,3 +1,3 @@
module Tabloid
- VERSION = "0.0.5"
+ VERSION = "0.0.6"
end
View
13 spec/lib/tabloid/data_spec.rb
@@ -39,6 +39,19 @@
(doc/"tr.summary td.col2").text.should == "6"
end
end
+ context "[sparse matrix]" do
+ let :data do
+ Tabloid::Data.new :report_columns => [Tabloid::ReportColumn.new(:col1, "Column 1"),
+ Tabloid::ReportColumn.new(:col2, "Column 2")],
+ :rows => [['a', 2], ['b', nil], ['c', 3]],
+ :summary => { :col2 => :sum }
+ end
+ it "should handle nil value" do
+ csv_rows = FasterCSV.parse data.to_csv
+ csv_rows.should include(["Totals", nil])
+ csv_rows.should include([nil, "5"])
+ end
+ end
context "[summary options is not presented]" do
let(:data) { Tabloid::Data.new(:report_columns => columns, :rows => rows ) }

0 comments on commit 0df55aa

Please sign in to comment.
Something went wrong with that request. Please try again.