Class: ReportBuilder::Builder::Pdf

Inherits:
ReportBuilder::Builder show all
Defined in:
lib/reportbuilder/builder/pdf.rb

Overview

Rtf Builder. Based on Prawn

Instance Attribute Summary collapse

Attributes inherited from ReportBuilder::Builder

#options, #parse_level, #toc

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ReportBuilder::Builder

#graph, #graph_entry, #image, #image_blob, #image_filename, inherited, inherited_classes, #parse_cycle, #parse_element, #section, #table, #table_entry, #toc_entry

Constructor Details

#initialize(builder, options) ⇒ Pdf

Creates a new Pdf object Params:

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

  • options: Hash of options.



16
17
18
19
20
21
# File 'lib/reportbuilder/builder/pdf.rb', line 16

def initialize(builder, options)
  super
  @pdf=Prawn::Document.new(options)
  @pdf.font_size=@options[:font_size]

end

Instance Attribute Details

#pdfObject

Pdf object.



11
12
13
# File 'lib/reportbuilder/builder/pdf.rb', line 11

def pdf
  @pdf
end

Class Method Details

.codeObject



23
24
25
# File 'lib/reportbuilder/builder/pdf.rb', line 23

def self.code
  %w{pdf}
end

Instance Method Details

#at_endObject



59
60
61
62
# File 'lib/reportbuilder/builder/pdf.rb', line 59

def at_end
  @pdf.number_pages(@options[:number_pages], [@pdf.bounds.right - 50, 0]  ) if @options[:numerate_pages]        
  
end

#default_optionsObject



33
34
35
36
37
# File 'lib/reportbuilder/builder/pdf.rb', line 33

def default_options
  {
    :font_size=>12
  }
end

#header(level, t) ⇒ Object

Add a header of level level with text t Level works similar to h



44
45
46
47
48
# File 'lib/reportbuilder/builder/pdf.rb', line 44

def header(level, t)
  @pdf.pad 5 do 
    @pdf.text t, {:size=>15-level*1.5,:align=>:center}
  end
end

#html(t) ⇒ Object

Do nothing on this builder



74
75
76
# File 'lib/reportbuilder/builder/pdf.rb', line 74

def html(t)
  # Nothing
end

#new_pageObject

Start a new page! (duh)



50
51
52
# File 'lib/reportbuilder/builder/pdf.rb', line 50

def new_page
  @pdf.start_new_page
end

#outObject

Returns pdf code for report



64
65
66
67
# File 'lib/reportbuilder/builder/pdf.rb', line 64

def out
  at_end
  @pdf.render
end

#parseObject



26
27
28
29
30
31
# File 'lib/reportbuilder/builder/pdf.rb', line 26

def parse
   unless @builder.no_title
     header(0,@builder.name)
   end
  parse_cycle(@builder)
end

#preformatted(t) ⇒ Object

Add preformatted text.



54
55
56
57
58
# File 'lib/reportbuilder/builder/pdf.rb', line 54

def preformatted(t)
  @pdf.font("Courier") do 
    @pdf.text t 
  end
end

#save(filename) ⇒ Object

Save pdf file



69
70
71
72
# File 'lib/reportbuilder/builder/pdf.rb', line 69

def save(filename)
  at_end
  @pdf.render_file(filename)
end

#text(t) ⇒ Object

Add a paragraph of text.



39
40
41
# File 'lib/reportbuilder/builder/pdf.rb', line 39

def text(t)
  @pdf.text(t)
end