Class: Ruport::Data::Group

Inherits:
Table
  • Object
show all
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

Attributes inherited from Table

#column_names, #data

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Controller::Hooks

#as, included, #save_as

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

#load, #parse

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(options={})
  @name = options.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

#nameObject

The name of the group



21
22
23
# File 'lib/ruport/data/grouping.rb', line 21

def name
  @name
end

#subgroupsObject

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: ==

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

Returns:

  • (Boolean)


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