Class: TableCloth::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/table_cloth/builder.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#presenterObject

Returns the value of attribute presenter.



3
4
5
# File 'lib/table_cloth/builder.rb', line 3

def presenter
  @presenter
end

#tableObject

Returns the value of attribute table.



3
4
5
# File 'lib/table_cloth/builder.rb', line 3

def table
  @table
end

Class Method Details

.build(objects, view, options = {}, &block) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/table_cloth/builder.rb', line 5

def self.build(objects, view, options={}, &block)
  if block_given?
    table = Class.new(TableCloth::Base)
    block.call(table)
  else
    table_class = options.delete(:with)
    table = table_class.kind_of?(String) ? table_class.constantize : table_class
  end

  presenter = options.delete(:present_with) || table.presenter

  new.tap do |builder|
    builder.table     = table
    builder.presenter = presenter.new(objects, table, view)
  end
end

Instance Method Details

#to_sObject



22
23
24
# File 'lib/table_cloth/builder.rb', line 22

def to_s
  presenter.render_table
end