Class: Ruport::Data::Group
- Includes:
- Controller::Hooks
- Defined in:
- lib/ruport/data/grouping.rb
Overview
Overview
This class implements a group data structure for Ruport. Group is simply a subclass of Table that adds a :name
attribute.
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
The name of the group.
-
#subgroups ⇒ Object
readonly
A hash of subgroups.
Attributes inherited from Table
Class Method Summary collapse
-
.inherited(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
(also: #==)
Compares this Group to another Group and returns
true
if thename
,data
, andcolumn_names
are equal. -
#initialize(options = {}) ⇒ Group
constructor
Creates a new Group based on the supplied options.
-
#initialize_copy(from) ⇒ Object
:nodoc:.
Methods included from Controller::Hooks
Methods inherited from Table
#+, #<<, #add_column, #add_columns, #add_row, #column, #feed_element, #method_missing, #pivot, #record_class, #reduce, #remove_column, #remove_columns, #rename_column, #rename_columns, #reorder, #replace_column, #row_search, #rows_with, #sigma, #sort_rows_by, #sort_rows_by!, #sub_table, #swap_column, #to_group, #to_s
Methods included from Table::FromCSV
Constructor Details
#initialize(options = {}) ⇒ Group
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]
41 42 43 44 45 |
# File 'lib/ruport/data/grouping.rb', line 41 def initialize(={}) @name = .delete(:name) @subgroups = {} super end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Ruport::Data::Table
Instance Attribute Details
#name ⇒ Object
The name of the group
21 22 23 |
# File 'lib/ruport/data/grouping.rb', line 21 def name @name end |
#subgroups ⇒ Object
A hash of subgroups
24 25 26 |
# File 'lib/ruport/data/grouping.rb', line 24 def subgroups @subgroups end |
Class Method Details
.inherited(base) ⇒ Object
:nodoc:
50 51 52 |
# File 'lib/ruport/data/grouping.rb', line 50 def self.inherited(base) #:nodoc: base.renders_as_group end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
76 77 78 |
# File 'lib/ruport/data/grouping.rb', line 76 def eql?(other) name.eql?(other.name) && super end |
#initialize_copy(from) ⇒ Object
:nodoc:
54 55 56 57 58 59 |
# File 'lib/ruport/data/grouping.rb', line 54 def initialize_copy(from) #:nodoc: super @name = from.name @subgroups = from.subgroups.inject({}) { |h,d| h.merge!({ d[0] => d[1].dup }) } end |