lib/pivot_table/grid.rb in pivot_table-0.1.3 vs lib/pivot_table/grid.rb in pivot_table-0.1.4

- old
+ new

@@ -16,18 +16,26 @@ end def build_rows @rows = [] @data_grid.each_with_index do |data, index| - @rows << Row.new(:header => row_headers[index], :data => data, :value_name => value_name) + @rows << Row.new( + :header => row_headers[index], + :data => data, + :value_name => value_name + ) end end def build_columns @columns = [] @data_grid.transpose.each_with_index do |data, index| - @columns << Column.new(:header => column_headers[index], :data => data, :value_name => value_name) + @columns << Column.new( + :header => column_headers[index], + :data => data, + :value_name => value_name + ) end end def column_headers headers @column_name @@ -36,19 +44,19 @@ def row_headers headers @row_name end def column_totals - columns.map{|c| c.total} + columns.map { |c| c.total } end def row_totals - rows.map{|r| r.total} + rows.map { |r| r.total } end def grand_total - column_totals.inject(0){|t,x| t + x} + column_totals.inject(0) { |t, x| t + x } end def prepare_grid @data_grid = [] row_headers.count.times do @@ -68,10 +76,11 @@ end @data_grid end private - def headers method + + def headers(method) @source_data.collect { |c| c.send method }.uniq.sort end end end