Class: Insurance::Formatter

Inherits:
Object
  • Object
show all
Includes:
ERB::Util
Defined in:
lib/insurance/formatter.rb

Class Method Summary collapse

Class Method Details

.run(filelist) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/insurance/formatter.rb', line 9

def self.run(filelist)
  files = filelist.keys.sort

  project_name    = File.basename Dir.pwd

  File.open("insurance/index.html", 'w') do |f|
    f.write ERB.new(File.read("#{File.dirname(__FILE__)}/templates/index.rhtml")).result(binding)
    puts "Wrote insurance/index.html"
  end

  filelist.each do |file, sf|
    sf.post_analyze!

    file_under_test = sf.name
    percentage      = sf.coverage_percent

    File.open("insurance/#{sf.name.gsub('/', '-')}.html", 'w') do |f|
      contents = File.open(sf.name, 'r').readlines
      body = "<pre class=\"ruby\">\n"
      contents.each_with_index do |line, num|
        unless sf.lines.include?(num + 1)
          body << "#{'%3s' % (num + 1).to_s}  <span class=\"unhit\">#{Syntax::Convertors::HTML.for_syntax('ruby').convert(line.chomp, false)}</span>\n"
        else
          body << "#{'%3s' % (num + 1).to_s}  #{Syntax::Convertors::HTML.for_syntax('ruby').convert(line, false)}"
        end
      end
      body << "</pre>"
      f.write ERB.new(File.read("#{File.dirname(__FILE__)}/templates/code-page.rhtml")).result(binding)
      puts "Wrote insurance/#{sf.name.gsub('/', '-')}.html"
    end
  end
end