Class: TableCreator::Table
- Inherits:
-
Object
- Object
- TableCreator::Table
- Includes:
- ActionView::Helpers::TagHelper
- Defined in:
- lib/table_creator/table.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#colgroups ⇒ Object
Returns the value of attribute colgroups.
Instance Method Summary collapse
- #<<(child) ⇒ Object
-
#initialize ⇒ Table
constructor
A new instance of Table.
- #to_csv ⇒ Object
- #to_html(opts = {}) ⇒ Object
Constructor Details
#initialize ⇒ Table
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
#children ⇒ Object
Returns the value of attribute children.
5 6 7 |
# File 'lib/table_creator/table.rb', line 5 def children @children end |
#colgroups ⇒ Object
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_csv ⇒ Object
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={}) content_tag :table, (colgroups + children).map(&:to_html).join.html_safe, opts end |