Class | Ruport::Data::Grouping |
In: |
lib/ruport/data/grouping.rb
|
Parent: | Object |
This class implements a grouping data structure for Ruport. A grouping is a collection of groups. It allows you to group the data in a table by one or more columns that you specify.
The data for a grouping is a hash of groups, keyed on each unique data point from the grouping column.
data | [RW] | The grouping‘s data |
grouped_by | [R] | The name of the column used to group the data |
Create a copy of the Grouping. Groups will be copied as well.
Example:
table = [[1,2,3],[4,5,6]].to_table(%w[a b c]) one = Ruport::Data::Grouping.new(a, :by => "a") two = one.dup
Provides a shortcut for the as() method by converting a call to to_format_name into a call to as(:format_name).
Useful for creating basic summaries from Grouping objects. Takes a field to summarize on, and then for each group, runs the specified procs and returns the results as a Table.
The following example would show for each date group, the sum for the attributes or methods :opened and :closed and order them by the :order array.
If :order is not specified, you cannot depend on predictable column order.
grouping.summary :date, :opened => lambda { |g| g.sigma(:opened) }, :closed => lambda { |g| g.sigma(:closed) }, :order => [:date,:opened,:closed]