class TableCreator::Table

Attributes

children[RW]
colgroups[RW]

Public Class Methods

new() click to toggle source
# File lib/table_creator/table.rb, line 7
def initialize
  @children = []
  @colgroups = []
  self
end

Public Instance Methods

<<(child) click to toggle source
# 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_csv() click to toggle source
# File lib/table_creator/table.rb, line 24
def to_csv
  @children.map(&:to_csv).join("\n")
end
to_html(opts={}) click to toggle source
# File lib/table_creator/table.rb, line 28
def to_html(opts={})
  content_tag :table, (colgroups + children).map(&:to_html).join.html_safe, opts
end