ReportBuilder::Table::TextBuilder

Text Builder for ReportBuilder::Table objects.

Uses Aaron Tinio’s text-table gem

Public Instance Methods

generate() click to toggle source
    # File lib/reportbuilder/table/textbuilder.rb, line 9
 9:       def generate()
10:         t=@element
11:         @rowspans=[]
12:         @builder.text(t.name)
13:         return if t.header.size+t.rows.size==0
14:         table = Text::Table.new do |tt|
15:           tt.head=t.header if t.header.size>0
16:           tt.rows=t.rows.map {|row| parse_row(row)}
17:         end
18:         #pp table.rows
19:         @builder.preformatted(table.to_s)
20:       end
parse_row(row) click to toggle source

Parse a row

    # File lib/reportbuilder/table/textbuilder.rb, line 22
22:       def parse_row(row)
23:         return :separator if row==:hr
24:         t=@element
25:         row_ary=[]
26:         real_i=0
27:         row.each_index do |i|
28:           extra=1
29:           
30:           while !@rowspans[real_i].nil? and @rowspans[real_i]>0
31:             @rowspans[real_i]-=1
32:             row_ary << ""
33:             real_i+=1
34:           end
35:           
36:           if row[i].is_a? ReportBuilder::Table::Rowspan
37:             @rowspans[real_i]=row[i].rows-1
38:             row_ary << row[i].to_s
39:           elsif row[i].is_a? ReportBuilder::Table::Colspan
40:             row_ary.push({:value=>row[i].to_s, :colspan=>row[i].cols})
41:             extra=row[i].cols
42:           elsif row[i].nil?
43:             row_ary.push("")
44:           else
45:             #size=row[i].to_s.size
46:             #puts sprintf("%i : %s (%d-%d)",i,row[i].to_s,@max_cols[i], size)
47:             row_ary.push(row[i].to_s)
48:           end
49:           real_i+=extra
50:         end
51:         row_ary
52:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.