Class: Blinkr::Report

Inherits:
Object
  • Object
show all
Defined in:
lib/blinkr/report.rb

Constant Summary collapse

TMPL =
File.expand_path('report.html.slim', File.dirname(__FILE__))

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context, engine, config) ⇒ Report

Returns a new instance of Report.



14
15
16
17
18
# File 'lib/blinkr/report.rb', line 14

def initialize context, engine, config
  @context = context
  @engine = engine
  @config = config
end

Class Method Details

.render(context, engine, config) ⇒ Object



10
11
12
# File 'lib/blinkr/report.rb', line 10

def self.render(context, engine, config)
  
end

Instance Method Details

#renderObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/blinkr/report.rb', line 20

def render
  @context.total = 0
  @context.severity = {}
  @context.category = {}
  @context.type = {}
  @context.pages.each do |_, page|
    page.max_severity = ::Blinkr::SEVERITY.first # :success
    page.errors.each do |error|
      raise "#{error.severity} not a valid severity. Must be one of #{::Blinkr::SEVERITY.join(',')}" unless ::Blinkr::SEVERITY.include? error.severity
      raise "#{error.category} must be specified." if error.category.nil?
      @context.total += 1
      @context.severity[error.severity] ||= OpenStruct.new({:count => 0})
      @context.severity[error.severity].count += 1
      page.max_severity = error.severity if ::Blinkr::SEVERITY.index(error.severity) > ::Blinkr::SEVERITY.index(page.max_severity)
      @context.category[error.category] ||= OpenStruct.new({:count => 0})
      @context.category[error.category].count += 1
      @context.type[error.type] ||= OpenStruct.new({:count => 0})
      @context.type[error.type].count += 1
    end
  end
  File.open(@config.report, 'w') do |file|
    file.write(Slim::Template.new(TMPL).render(OpenStruct.new({:blinkr => @context, :engine => @engine,
                                                               :errors => @context.to_json})))
  end
  
  puts "Wrote report to #{@config.report}" if @config.verbose
end