Class: Ruport::Data::Table::RosePivot
- Inherits:
-
Pivot
- Object
- Pivot
- Ruport::Data::Table::RosePivot
- Defined in:
- lib/rose/ruport.rb
Overview
Enables using value blocks for the value column
Instance Method Summary collapse
Instance Method Details
#to_table ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rose/ruport.rb', line 26 def to_table result = Ruport::Data::RoseTable.new() result.add_column(@group_column) pivoted_columns = columns_from_pivot pivoted_columns.each { |name| result.add_column(name) } outer_grouping = Grouping(@table, :by => @group_column) group_column_entries.each {|outer_group_name| outer_group = outer_grouping[outer_group_name] pivot_values = pivoted_columns.inject({}) do |hsh, pc| matching_rows = outer_group.rows_with(@pivot_column => pc) hsh[pc] = yield(matching_rows) hsh end result << [outer_group_name] + pivoted_columns.map {|pc| pivot_values[pc] } } result end |