Parent

ReportBuilder::Table

Creates a table. Use:

  table=ReportBuilder::Table.new(:header =>["id","city","name","code1","code2"])
  table.row([1, Table.rowspan("New York",3), "Ringo", Table.colspan("no code",2),nil])
  table.row([2, nil,"John", "ab-1","ab-2"])
  table.row([3, nil,"Paul", "ab-3"])
  table.hr
  table.row([4, "London","George", Table.colspan("ab-4",2),nil])
  puts table
    ==>
  -----------------------------------------
  | id | city     | name  | code1 | code2 |
  -----------------------------------------
  | 1  | New York | Ringo | no code       |
  | 2  |          | John  | ab-1  | ab-2  |
  | 3  |          | Paul  | ab-3  |       |
  -----------------------------------------
  | 4  | London   |George | ab-4          |
  -----------------------------------------

Constants

DEFAULT_OPTIONS

Attributes

header[RW]

Array of headers

name[RW]

Array of headers

max_cols[R]

Size for each column

rows[R]

Array of rows

Public Class Methods

new(opts=Hash.new, &block) click to toggle source

Create a new table. Options: :name, :header Use:

  table=ReportBuilder::Table.new(:header =>["var1","var2"])
    # File lib/reportbuilder/table.rb, line 38
38:     def initialize(opts=Hash.new, &block)
39:       raise ArgumentError,"opts should be a Hash" if !opts.is_a? Hash
40:       opts=DEFAULT_OPTIONS.merge opts
41:       if opts[:name].nil?
42:         @name= "Table #{@@n}"
43:         @@n+=1
44:       else
45:         @name=opts[:name]
46:       end
47:       @header=opts[:header]
48:       @rows=[]
49:       @max_cols=[]
50:       if block
51:         block.arity<1 ? self.instance_eval(&block) : block.call(self)
52:       end
53:     end

Public Instance Methods

colspan(data,n) click to toggle source

Adds a colspan on a cell

  table.add_row(["a",table.colspan("b",2)])
    # File lib/reportbuilder/table.rb, line 83
83:     def colspan(data,n)
84:       Colspan.new(data,n)
85:     end
horizontal_line() click to toggle source
Alias for: hr
hr() click to toggle source

Adds a horizontal rule

  table.add_hr
    # File lib/reportbuilder/table.rb, line 65
65:     def hr
66:       @rows.push(:hr)
67:     end
Also aliased as: horizontal_line
n_columns() click to toggle source
    # File lib/reportbuilder/table.rb, line 60
60:     def n_columns
61:       @n_columns||=calculate_widths.size
62:     end
n_rows() click to toggle source
    # File lib/reportbuilder/table.rb, line 78
78:     def n_rows
79:       @rows.size
80:     end
n_rows_no_hr() click to toggle source

Count the numbers of rows without :hr

    # File lib/reportbuilder/table.rb, line 75
75:     def n_rows_no_hr
76:       @rows.inject(0) {|ac,v| ac+(v==:hr ? 0 : 1)}
77:     end
report_building_html(builder) click to toggle source
     # File lib/reportbuilder/table.rb, line 117
117:     def report_building_html(builder)
118:       require 'reportbuilder/table/htmlbuilder'
119:       table_builder=ReportBuilder::Table::HtmlBuilder.new(builder, self)
120:       table_builder.generate
121:     end
report_building_rtf(builder) click to toggle source
     # File lib/reportbuilder/table.rb, line 122
122:     def report_building_rtf(builder)
123:       require 'reportbuilder/table/rtfbuilder'
124:       table_builder=ReportBuilder::Table::RtfBuilder.new(builder, self)
125:       table_builder.generate
126:     end
report_building_text(builder) click to toggle source
     # File lib/reportbuilder/table.rb, line 112
112:     def report_building_text(builder)
113:       require 'reportbuilder/table/textbuilder'
114:       table_builder=ReportBuilder::Table::TextBuilder.new( builder, self)
115:       table_builder.generate
116:     end
row(row) click to toggle source

Adds a row Usage:

  table.add_row(%w{1 2})
    # File lib/reportbuilder/table.rb, line 57
57:     def row(row)
58:       @rows.push(row)
59:     end
rowspan(data,n) click to toggle source

Adds a rowspan on a cell

  table.add_row(["a",table.rowspan("b",2)])
    # File lib/reportbuilder/table.rb, line 71
71:     def rowspan(data,n)
72:       Rowspan.new(data,n)
73:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.