Included Modules

ReportBuilder::Builder::Rtf

Rtf Builder. Based on ruby-rtf (ruby-rtf.rubyforge.org/).

Attributes

rtf[RW]

RTF::Document object. See ruby-rtf.rubyforge.org/ for documentation

Public Class Methods

code() click to toggle source
    # File lib/reportbuilder/builder/rtf.rb, line 44
44:       def self.code
45:         %{rtf}
46:       end
new(builder, options) click to toggle source

Creates a new Rtf object Params:

  • builder: A ReportBuilder::Builder object or other with same interface

  • options: Hash of options.

    • :font: Font family. Default to “Times New Roman“

    • :font_size: Font size. Default to 20

    • :table_border_width

    • :table_hr_width

    # File lib/reportbuilder/builder/rtf.rb, line 21
21:       def initialize(builder, options)
22:         super
23:         @font=Font.new(Font::ROMAN, @options[:font])
24:         
25:         @rtf = Document.new(@font)
26:         @pre_char = CharacterStyle.new
27:         
28:         @pre_char.font = Font.new(Font::MODERN, 'Courier')
29:         @pre_char.font_size=@options[:font_size]
30:         
31:         @pre_par  = ParagraphStyle.new
32:         
33:         @header_styles=Hash.new {|h,k|
34:           cs=CharacterStyle.new
35:           cs.font=@font
36:           cs.font_size=@options[:font_size]+(8-k)*2
37:           cs.bold=true
38:           ps=ParagraphStyle.new
39:           ps.justification = ParagraphStyle::CENTER_JUSTIFY
40:           h[k]={:cs=>cs, :ps=>ps}
41:         }        
42:       end

Public Instance Methods

default_options() click to toggle source
    # File lib/reportbuilder/builder/rtf.rb, line 49
49:       def default_options
50:         
51:         {
52:           :font=>'Times New Roman',
53:           :font_size=>20,
54:           :table_border_width=>3,
55:           :table_hr_width=>25
56:         }
57:       end
header(level,t) click to toggle source

Add a header of level level with text t

    # File lib/reportbuilder/builder/rtf.rb, line 67
67:       def header(level,t)
68:         @rtf.paragraph(@header_styles[level][:ps]) do |n1|
69:           n1.apply(@header_styles[level][:cs]) do |n2|
70:             n2.line_break
71:             n2 << t
72:             n2.line_break
73:           end
74:         end
75:       end
html(t) click to toggle source

Do nothing on this builder

     # File lib/reportbuilder/builder/rtf.rb, line 98
 98:       def html(t)
 99:         # Nothing
100:       end
out() click to toggle source

Returns rtf code for report

    # File lib/reportbuilder/builder/rtf.rb, line 89
89:       def out
90:         @rtf.to_rtf
91:       end
preformatted(t) click to toggle source

Add preformatted text. By default, uses Courier

    # File lib/reportbuilder/builder/rtf.rb, line 77
77:       def preformatted(t)
78:         @rtf.paragraph(@pre_par) do |n1|
79:           n1.apply(@pre_char) do |n2|
80:             t.split("\n").each do |line|
81:               n2 << line
82:               n2.line_break
83:             end
84:           end
85:         end
86:         
87:       end
save(filename) click to toggle source

Save rtf file

    # File lib/reportbuilder/builder/rtf.rb, line 93
93:       def save(filename)
94:         File.open(filename,'wb')  {|file| file.write(@rtf.to_rtf)
95:         }
96:       end
text(*args,&block) click to toggle source

Add a paragraph of text.

    # File lib/reportbuilder/builder/rtf.rb, line 59
59:       def text(*args,&block)
60:         if args.size==1 and args[0].is_a? String and !block
61:           @rtf.paragraph << args[0]
62:         else
63:           @rtf.paragraph(*args,&block)
64:         end
65:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.