Class: TableCreator::RowGroup
- Inherits:
-
Object
- Object
- TableCreator::RowGroup
- Includes:
- ActionView::Helpers::TagHelper
- Defined in:
- lib/table_creator/row_group.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#options ⇒ Object
Returns the value of attribute options.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #<<(child) ⇒ Object
-
#initialize(row_group, parent, type = :body, options = nil) ⇒ RowGroup
constructor
A new instance of RowGroup.
- #to_csv ⇒ Object
- #to_html ⇒ Object
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, = nil) @parent = parent @children = [] @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
#children ⇒ Object
Returns the value of attribute children.
8 9 10 |
# File 'lib/table_creator/row_group.rb', line 8 def children @children end |
#options ⇒ Object
Returns the value of attribute options.
8 9 10 |
# File 'lib/table_creator/row_group.rb', line 8 def @options end |
#parent ⇒ Object
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_csv ⇒ Object
30 31 32 |
# File 'lib/table_creator/row_group.rb', line 30 def to_csv @children.map(&:to_csv).join("\n") end |
#to_html ⇒ Object
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 content_tag tag, children.map(&:to_html).join.html_safe, end |