Class: Reviser::Components::Generator

Inherits:
Reviser::Component show all
Includes:
Generators
Defined in:
lib/reviser/components/generator.rb

Overview

Generator is used to create a file result after the analysis. Currently, Generator supports HTML, XLS and CSV format.

Author:

  • Renan Strauss

  • Yann Prono

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Generators

#csv, #html, #xls

Methods inherited from Reviser::Component

#resource, #work

Constructor Details

#initialize(data) ⇒ Generator

Returns a new instance of Generator.



39
40
41
# File 'lib/reviser/components/generator.rb', line 39

def initialize(data)
	super data
end

Class Method Details

.titleize(str) ⇒ String

Quite handy

Parameters:

  • str (String)

    string to titleize

Returns:



73
74
75
# File 'lib/reviser/components/generator.rb', line 73

def self.titleize(str)
	str.split(/_/).join(' ').capitalize
end

Instance Method Details

#criteriasArray

Gets all criterias of marking used to display informations in documents.

Returns:

  • (Array)

    Array with all criterias.



66
67
68
# File 'lib/reviser/components/generator.rb', line 66

def criterias
	@data.values.first.keys.unshift.map! { |cri| Generator.titleize(cri.to_s) }
end

#runObject

Runs the generation of results file in all asked formats by user.



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/reviser/components/generator.rb', line 44

def run
	i = 0
	Cfg[:out_format].each do |format|
		# Deep copy !!!
		arg = Marshal.load(Marshal.dump(@data))

		puts "----[#{i+1}/#{Cfg[:out_format].size}] #{format.upcase}"
		arg.each do |project, results|
			results.each do |criterion, value|
				arg[project][criterion] = value.send(format.to_sym).to_s.encode! 'utf-8', :invalid => :replace
			end
		end

		send format.to_sym, arg

		i += 1
	end
end