class Ruport::Data::Group
Overview¶ ↑
This class implements a group data structure for Ruport. Group is
simply a subclass of Table that adds a
:name
attribute.
Attributes
name[R]
The name of the group
subgroups[R]
A hash of subgroups
Public Class Methods
new(options={})
click to toggle source
Creates a new Group based on the supplied options.
Valid options:
:name
-
The name of the Group
:data
-
An Array of Arrays representing the records in this Group
:column_names
-
An Array containing the column names for this Group.
Example:
group = Group.new :name => 'My Group', :data => [[1,2,3], [3,4,5]], :column_names => %w[a b c]
Calls superclass method
# File lib/ruport/data/grouping.rb, line 41 def initialize(options={}) @name = options.delete(:name) @subgroups = {} super end
Public Instance Methods
eql?(other)
click to toggle source
Compares this Group to another Group and returns true
if the
name
, data
, and column_names
are
equal.
Example:
one = Group.new :name => 'test', :data => [[1,2], [3,4]], :column_names => %w[a b] two = Group.new :name => 'test', :data => [[1,2], [3,4]], :column_names => %w[a b] one.eql?(two) #=> true
Calls superclass method
# File lib/ruport/data/grouping.rb, line 76 def eql?(other) name.eql?(other.name) && super end
Also aliased as: ==
Private Instance Methods
create_subgroups(group_column)
click to toggle source
Creates subgroups for the group based on the supplied column name. Each subgroup is a hash whose keys are the unique values in the column.
Example:
main_group = Group.new :name => 'test', :data => [[1,2,3,4,5], [3,4,5,6,7]], :column_names => %w[a b c d e] main_group.create_subgroups("a")
# File lib/ruport/data/grouping.rb, line 98 def create_subgroups(group_column) if @subgroups.empty? @subgroups = grouped_data(group_column) else @subgroups.each {|name,group| group.send(:create_subgroups, group_column) } end end