19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/blinkr/report.rb', line 19
def render
@context.severities = {}
@context.categories = {}
@context.types = {}
@context.pages.each do |url, page|
page.max_severity = 'success'
page.errors.each do |error|
raise "#{error.severity} not a valid severity. Must be one of #{SEVERITY.join(',')}" unless SEVERITY.include? error.severity
raise "#{error.category} must be specified." if error.category.nil?
@context.severities[error.severity] ||= OpenStruct.new({ :id => error.severity, :count => 0 })
@context.severities[error.severity].count += 1
page.max_severity = error.severity if SEVERITY.index(error.severity) > SEVERITY.index(page.max_severity)
@context.categories[error.category] ||= OpenStruct.new({ :id => @context.categories.length, :count => 0, :severities => Hash.new(0), :types => {} })
@context.categories[error.category].severities[error.severity] += 1
@context.categories[error.category].types[error.type] ||= OpenStruct.new({ :id => @context.categories[error.category].types.length, :count => 0, :severities => Hash.new(0) })
@context.categories[error.category].types[error.type].severities[error.severity] += 1
end
end
@context.error_count = @context.severities.reduce(0){ |sum, (severity, metadata)| sum += metadata.count }
File.open(@config.report, 'w') { |file| file.write(Slim::Template.new(TMPL).render(OpenStruct.new({ :blinkr => @context, :engine => @engine }))) }
end
|