Class: TableCreator::Table

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTable

Returns a new instance of Table.



7
8
9
10
11
# File 'lib/table_creator/table.rb', line 7

def initialize
  @children = []
  @colgroups = []
  self
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



5
6
7
# File 'lib/table_creator/table.rb', line 5

def children
  @children
end

#colgroupsObject

Returns the value of attribute colgroups.



5
6
7
# File 'lib/table_creator/table.rb', line 5

def colgroups
  @colgroups
end

Instance Method Details

#<<(child) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/table_creator/table.rb', line 13

def <<(child)
  if child.is_a? Array
    @children << Row.new(child, self)

  else # hash of one or more types
    [:header, :footer, :body].each do |type|
      @children << RowGroup.new(child[type], self, type) if child[type]
    end
  end
end

#to_csvObject



24
25
26
# File 'lib/table_creator/table.rb', line 24

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

#to_html(opts = {}) ⇒ Object



28
29
30
# File 'lib/table_creator/table.rb', line 28

def to_html(opts={})
   :table, (colgroups + children).map(&:to_html).join.html_safe, opts
end