Parent

ReportBuilder::Builder

Abstract Builder. A builder is a class which control the output for a ReportBuilder object Every object which have a # method could be parsed with # method.

Attributes

parse_level[R]

Level of heading. See ReportBuilder::Section for using it.

options[R]

Options for Builder. Passed by ReportBuilder class on creation

toc[R]

Entries for Table of Contents

Public Class Methods

code() click to toggle source

Array of string with format names for the Builder. For example, Html builder returns %w{html htm} and Text builde returns %w{text txt}

    # File lib/reportbuilder/builder.rb, line 16
16:     def self.code
17: #      raise "Implement this"
18:     end
inherited(subclass) click to toggle source
    # File lib/reportbuilder/builder.rb, line 22
22:     def self.inherited(subclass)
23:       inherited_classes << subclass
24:     end
inherited_classes() click to toggle source
    # File lib/reportbuilder/builder.rb, line 19
19:     def self.inherited_classes
20:       @@inherited_classes||=Array.new
21:     end
new(builder, options) click to toggle source
    # File lib/reportbuilder/builder.rb, line 25
25:     def initialize(builder, options)
26:       @builder=builder
27:       @parse_level=0
28:       @options=default_options.merge(options)
29:       @toc=[]
30:       @table_n=1
31:       @entry_n=1
32:       @list_tables=[]
33: 
34:     end

Public Instance Methods

html(t) click to toggle source

Add html code. Only parsed with builder which understand html

    # File lib/reportbuilder/builder.rb, line 95
95:     def html(t)
96:       raise "Implement this"
97:     end
image(filename,opt=Hash.new) click to toggle source

Create and parse an image.

    # File lib/reportbuilder/builder.rb, line 82
82:     def image(filename,opt=Hash.new)
83:       parse_element(ReportBuilder::Image.new(filename,opt))
84:     end
parse() click to toggle source

Parse the output. Could be reimplemented on subclasses

    # File lib/reportbuilder/builder.rb, line 36
36:     def parse
37:       parse_cycle(@builder)
38:     end
parse_cycle(container) click to toggle source

Parse each # of the container

    # File lib/reportbuilder/builder.rb, line 51
51:     def parse_cycle(container)
52:       @parse_level+=1
53:       container.elements.each do |element|
54:         parse_element(element)
55:       end
56:       @parse_level-=1
57:     end
parse_element(element) click to toggle source

Parse one object, using this workflow

  • If is a block, evaluate it

  • Use #, where CODE is one of the codes defined by #

  • Use #

  • Use #

    # File lib/reportbuilder/builder.rb, line 64
64:     def parse_element(element)
65:       methods=self.class.code.map {|m| ("report_building_"+m).intern}
66:       
67:       if element.is_a? Proc
68:         element.arity<1 ? instance_eval(&element) : element.call(self)
69:       elsif method=methods.find {|m| element.respond_to? m}
70:         element.send(method, self)
71:       elsif element.respond_to? :report_building
72:         element.send(:report_building, self)
73:       else
74:         text(element.to_s)
75:       end
76:     end
preformatted(t) click to toggle source

Add preformatted text

     # File lib/reportbuilder/builder.rb, line 99
 99:     def preformatted(t)
100:       raise "Implement this"
101:     end
save(filename) click to toggle source

Save the output of builder to a file

    # File lib/reportbuilder/builder.rb, line 40
40:     def save(filename)
41:       File.open(filename, "wb") do |fp|
42:         fp.write(out)
43:       end
44:     end
section(opt=Hash.new, &block) click to toggle source

Create and parse an image. Use a block to insert element inside the block

    # File lib/reportbuilder/builder.rb, line 86
86:     def section(opt=Hash.new, &block)
87:       parse_element(ReportBuilder::Section.new(opt,&block))
88:     end
table(opt=Hash.new, &block) click to toggle source

Create and parse a table. Use a block to control the table

    # File lib/reportbuilder/builder.rb, line 78
78:     def table(opt=Hash.new, &block)
79:       parse_element(ReportBuilder::Table.new(opt,&block))
80:     end
table_entry(name) click to toggle source

Add an entry for table index. Returns the name of the anchor

     # File lib/reportbuilder/builder.rb, line 113
113:     def table_entry(name)
114:       anchor="table_#{@table_n}"
115:       @table_n+=1
116:       @list_tables.push([anchor,name])
117:       anchor
118:     end
text(t) click to toggle source

Add a paragraph to the report

    # File lib/reportbuilder/builder.rb, line 91
91:     def text(t)
92:       raise "Implement this"
93:     end
toc_entry(name) click to toggle source

Add a TOC (Table of Contents) entry Return the name of anchor

     # File lib/reportbuilder/builder.rb, line 104
104:     def toc_entry(name)
105:       anchor="toc_#{@entry_n}"
106:       @entry_n+=1
107:       @toc.push([anchor, name, parse_level])
108:       anchor
109:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.