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.

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:

  • (String)

    cute string !



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

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.



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

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
# File 'lib/reviser/components/generator.rb', line 44

def run
  #begin
    Cfg[:out_format].each do |format|
      # Deep copy !!!
      arg = Marshal.load(Marshal.dump(@data))
      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
    end
  #rescue Object => e
  #  @logger.h1 Logger::FATAL, "Wrong format : #{e.to_s}"
  #end
end