Class: Risu::Base::Templater

Inherits:
Object
  • Object
show all
Defined in:
lib/risu/base/templater.rb

Overview

Templater class for generating a report from a ERB template

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(template, findings, output, template_manager) ⇒ Templater

Setups of the Templater class initializing all of the variables



32
33
34
35
36
37
# File 'lib/risu/base/templater.rb', line 32

def initialize template, findings, output, template_manager
	@template = template
	@findings = findings
	@output_file = output
	@template_manager = template_manager
end

Instance Attribute Details

#findingsObject

Returns the value of attribute findings.



27
28
29
# File 'lib/risu/base/templater.rb', line 27

def findings
  @findings
end

#output_fileObject

Returns the value of attribute output_file.



27
28
29
# File 'lib/risu/base/templater.rb', line 27

def output_file
  @output_file
end

#templateObject

Returns the value of attribute template.



27
28
29
# File 'lib/risu/base/templater.rb', line 27

def template
  @template
end

#template_managerObject

Returns the value of attribute template_manager.



27
28
29
# File 'lib/risu/base/templater.rb', line 27

def template_manager
  @template_manager
end

Instance Method Details

#generateObject

Generates a report based on the ERB template



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/risu/base/templater.rb', line 40

def generate
	begin
		template = @template
		template_manager = @template_manager

		t = template_manager.find_template_by_name(template)
		t = t.class.new

		if t.template_info[:renderer] == "CSV"
			Risu::Renderers::CSVRenderer.generate(@output_file) do |output|
				t = template_manager.find_template_by_name(template)
				t = t.class.new
				t.output = output
				t.render(output) unless t == nil
			end
		elsif t.template_info[:renderer] == "PDF"
			Prawn::Document.generate(@output_file, :margin => [75, 50, 75, 50]) do |output|
				output.font_size 10
				t = template_manager.find_template_by_name(template)
				t = t.class.new
				t.output = output
				t.render(output) unless t == nil
			end
		end
	rescue => e
		raise unless Rails.env.production?
		puts "Templater Error: #{e.message} \n #{e.backtrace.join("\n\t")}\n"
	end
end