Sha256: edcf96df60f97084140743b4453f14bd5e6f40a7ee1478a2e76a7489f17df70f

Contents?: true

Size: 668 Bytes

Versions: 11

Compression:

Stored size: 668 Bytes

Contents

module TableCloth
  class Builder
    attr_accessor :table, :presenter

    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

    def initialize
    end

    def to_s
      presenter.render_table
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
table_cloth-0.3.1.alpha1 lib/table_cloth/builder.rb
table_cloth-0.3.0.beta3 lib/table_cloth/builder.rb
table_cloth-0.3.0.beta2 lib/table_cloth/builder.rb
table_cloth-0.3.0.beta1 lib/table_cloth/builder.rb
table_cloth-0.2.3 lib/table_cloth/builder.rb
table_cloth-0.2.2 lib/table_cloth/builder.rb
table_cloth-0.2.1 lib/table_cloth/builder.rb
table_cloth-0.2.0 lib/table_cloth/builder.rb
table_cloth-0.1.2 lib/table_cloth/builder.rb
table_cloth-0.1.1 lib/table_cloth/builder.rb
table_cloth-0.1.0 lib/table_cloth/builder.rb