Class: TableCreator::RowGroup

Inherits:
Object
  • Object
show all
Includes:
ActionView::Helpers::TagHelper
Defined in:
lib/table_creator/row_group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(row_group, parent, type = :body, options = nil) ⇒ RowGroup

Returns a new instance of RowGroup.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/table_creator/row_group.rb', line 10

def initialize(row_group, parent, type = :body, options = nil)
  @parent = parent
  @children = []
  @options = options
  @type = type

  row_group.each do |row|
    if row.is_a? Hash
      @children << Row.new(row[:data], self, row.except(:data).merge(:type => type))
    else
      @children << Row.new(row, self, :type => type)
    end
  end
  self
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



8
9
10
# File 'lib/table_creator/row_group.rb', line 8

def children
  @children
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/table_creator/row_group.rb', line 8

def options
  @options
end

#parentObject

Returns the value of attribute parent.



8
9
10
# File 'lib/table_creator/row_group.rb', line 8

def parent
  @parent
end

Instance Method Details

#<<(child) ⇒ Object



26
27
28
# File 'lib/table_creator/row_group.rb', line 26

def <<(child)
  @children << Row.new(child, self, :type => type)
end

#to_csvObject



30
31
32
# File 'lib/table_creator/row_group.rb', line 30

def to_csv
  @children.map(&:to_csv).join("\n")
end

#to_htmlObject



34
35
36
37
# File 'lib/table_creator/row_group.rb', line 34

def to_html
  tag = case @type; when :header; :thead; when :footer; :tfoot; else :tbody; end
   tag, children.map(&:to_html).join.html_safe, options
end