class Reviser::Components::Generator

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

@author Renan Strauss @author Yann Prono

Public Class Methods

new(data) click to toggle source
Calls superclass method Reviser::Component::new
# File lib/reviser/components/generator.rb, line 39
def initialize(data)
        super data
end
titleize(str) click to toggle source

Quite handy @param str [String] string to titleize @return [String] cute string !

# File lib/reviser/components/generator.rb, line 73
def self.titleize(str)
        str.split(/_/).join(' ').capitalize
end

Public Instance Methods

criterias() click to toggle source

Gets all criterias of marking used to display informations in documents. @return [Array] Array with all criterias.

# File lib/reviser/components/generator.rb, line 66
def criterias
        @data.values.first.keys.unshift.map! { |cri| Generator.titleize(cri.to_s) }
end
run() click to toggle source

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

# 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