Class: EasyTable::TableBuilder

Inherits:
Object
  • Object
show all
Includes:
Components::Columns, Components::Spans
Defined in:
lib/easy_table/table_builder.rb

Defined Under Namespace

Modules: M

Instance Method Summary collapse

Methods included from Components::Spans

#span

Methods included from Components::Columns

#column

Constructor Details

#initialize(collection, template, options) ⇒ TableBuilder

Returns a new instance of TableBuilder.



23
24
25
26
27
28
# File 'lib/easy_table/table_builder.rb', line 23

def initialize(collection, template, options)
  @collection = collection
  @options, @tr_opts = parse_options(options)
  @template = template
  @node = Tree::TreeNode.new('root')
end

Instance Method Details

#buildObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/easy_table/table_builder.rb', line 30

def build
  (:table, @options) do
    concat((:thead) do
      thead
    end)
    concat((:tbody) do
      @collection.each do |record|
        concat((:tr, tr_opts(record)) do
          node.each_leaf do |leaf|
            leaf.content.td(record)
          end
        end)
      end
    end)
  end
end