Sha256: fb4a3ac3d29f720b9aa7272e56ef0a6605ac5f12a6f676d635f63d724e7b08f3

Contents?: true

Size: 677 Bytes

Versions: 5

Compression:

Stored size: 677 Bytes

Contents

module TableCreator
  class Table
    include ActionView::Helpers::TagHelper

    attr_accessor :children, :colgroups

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

    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

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

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
table_creator-0.4.0 lib/table_creator/table.rb
table_creator-0.3.0 lib/table_creator/table.rb
table_creator-0.2.0 lib/table_creator/table.rb
table_creator-0.1.1 lib/table_creator/table.rb
table_creator-0.1.0 lib/table_creator/table.rb