Parent

ReportBuilder

Report Abstract Interface.

Creates text, html and rtf output, based on a common framework.

Use

1) Using generic ReportBuilder#add, every object will be parsed using methods report_building_FORMAT, # or #

 require "reportbuilder"    
 rb=ReportBuilder.new
 rb.add(2) #  Int#to_s used
 section=ReportBuilder::Section.new(:name=>"Section 1")
 table=ReportBuilder::Table.new(:name=>"Table", :header=>%w{id name})
 table.row([1,"John"])
 table.hr
 table.row([2,"Peter"])
 section.add(table) #  Section is a container for other methods
 rb.add(section) #  table have a #report_building method
 rb.add("Another text") #  used directly
 rb.name="Text output"
 puts rb.to_text
 rb.name="Html output"
 puts rb.to_html

2) Using a block, you can control directly the builder

 require "reportbuilder"    
 rb=ReportBuilder.new do
  text("2")
  section(:name=>"Section 1") do
   table(:name=>"Table", :header=>%w{id name}) do
    row([1,"John"])
    hr
    row([2,"Peter"])
   end
  end
  preformatted("Another Text")
 end
 rb.name="Text output"
 puts rb.to_text
 rb.name="Html output"
 puts rb.to_html

Constants

VERSION

ReportBuilder version

FormatNotFound

Attributes

elements[R]
name[RW]

Name of report

no_title[RW]

Doesn’t print a title if set to true

Public Class Methods

builder_for(format) click to toggle source

Available formats

    # File lib/reportbuilder.rb, line 58
58:   def self.builder_for(format)
59:     format=format.to_s.downcase
60:     Builder.inherited_classes.find {|m| m.code.include? format} 
61:   end
generate(options=Hash.new, &block) click to toggle source

Generates and optionally save the report on one function

    # File lib/reportbuilder.rb, line 63
63:   def self.generate(options=Hash.new, &block)
64:     options[:filename]||=nil
65:     options[:format]||="text"
66:     
67:     if options[:filename] and options[:filename]=~/\.(\w+?)$/
68:       options[:format]=$1
69:     end
70:     file=options.delete(:filename)
71:     format=options.delete(:format)
72:     rb=ReportBuilder.new(options)
73:     rb.add(block)
74:     begin
75:       builder=builder_for(format).new(rb, options)
76:     rescue NameError  => e
77:       raise FormatNotFound.new(e)
78:     end
79:     builder.parse
80:     out=builder.out
81:     unless file.nil?
82:       File.open(file,"wb") do |fp|
83:         fp.write out
84:       end
85:     else
86:       out
87:     end
88:   end
new(options=Hash.new, &block) click to toggle source

Create a new Report

    # File lib/reportbuilder.rb, line 90
90:   def initialize(options=Hash.new, &block)
91:     options[:name]||="Report "+Time.new.to_s
92:     @no_title=options.delete :no_title
93:     @name=options.delete :name 
94:     @options=options
95:     @elements=Array.new
96:     add(block) if block
97:   end

Public Instance Methods

add(element) click to toggle source

Add an element to the report. If parameters is an object which respond to :to_reportbuilder, this method will called. Otherwise, the element itself will be added

     # File lib/reportbuilder.rb, line 102
102:   def add(element)
103:     @elements.push(element)
104:     self
105:   end
save_html(file) click to toggle source

Save an html file

     # File lib/reportbuilder.rb, line 125
125:   def save_html(file)
126:     options=@options.dup
127:     options[:directory]=File.dirname(file)
128:     gen=Builder::Html.new(self, options)
129:     gen.parse
130:     gen.save(file)
131:   end
save_rtf(filename) click to toggle source

Save a rtf file

     # File lib/reportbuilder.rb, line 119
119:   def save_rtf(filename)
120:     gen = Builder::Rtf.new(self,@options)
121:     gen.parse
122:     gen.save(filename)
123:   end
to_html() click to toggle source

Returns an Html output

     # File lib/reportbuilder.rb, line 107
107:   def to_html()
108:     gen = Builder::Html.new(self,@options)
109:     gen.parse
110:     gen.out
111:   end
to_rtf() click to toggle source

Returns a RTF output

     # File lib/reportbuilder.rb, line 113
113:   def to_rtf()
114:     gen = Builder::Rtf.new(self, @options)
115:     gen.parse
116:     gen.out
117:   end
to_s() click to toggle source
Alias for: to_text
to_text() click to toggle source

Returns a Text output

     # File lib/reportbuilder.rb, line 133
133:   def to_text()
134:     gen=Builder::Text.new(self, @options)
135:     gen.parse 
136:     gen.out
137:   end
Also aliased as: to_s

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.