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.



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

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

Class Method Details

.render(context, engine, config) ⇒ Object



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

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

Instance Method Details

#renderObject



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, )| sum += .count }
  File.open(@config.report, 'w') { |file| file.write(Slim::Template.new(TMPL).render(OpenStruct.new({ :blinkr => @context, :engine => @engine }))) }
end