Class: ReportBuilder::Table::PdfBuilder

Inherits:
ElementBuilder show all
Defined in:
lib/reportbuilder/table/pdfbuilder.rb

Overview

Text Builder for ReportBuilder::Table objects.

Uses Aaron Tinio’s text-table gem

Instance Method Summary collapse

Methods inherited from ElementBuilder

#initialize

Constructor Details

This class inherits a constructor from ReportBuilder::ElementBuilder

Instance Method Details

#generateObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/reportbuilder/table/pdfbuilder.rb', line 10

def generate()
  t=@element
  @pdf=@builder.pdf
  @rowspans=[]
  if !t.nil? and t.name!=""
    @pdf.pad_top 10 do
      @pdf.text t.name, {:size=>12, :align=>:center} 
    end
  end
  return if t.header.size+t.rows.size==0
  has_header=t.header.size>0
  @pdf.pad(10) do 
    if has_header
      t_options=t.options.merge({:headers=>t.header, :align_headers=>:center})
      @pdf.table(t.rows.map{|row| parse_row(row)}, t_options) do
        row(0).style(:font_style => :bold, :background_color => 'cccccc')
      end
    else
      @pdf.table(t.rows.map{|row| parse_row(row)}, t.options) 
    end
  end
end

#parse_row(row) ⇒ Object

Parse a row



33
34
35
36
37
38
39
# File 'lib/reportbuilder/table/pdfbuilder.rb', line 33

def parse_row(row)
  if row==:hr
    []
  else
    row
  end
end