Class: SimplecovCovview::CovView

Inherits:
Object
  • Object
show all
Defined in:
lib/simplecov_covview/line.rb,
lib/simplecov_covview/color.rb,
lib/simplecov_covview/srcfile.rb,
lib/simplecov_covview/formatter.rb,
lib/simplecov_covview/resultfile.rb

Defined Under Namespace

Classes: Resultfile, Srcfile

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(result) ⇒ CovView

Returns a new instance of CovView.



5
6
7
8
# File 'lib/simplecov_covview/formatter.rb', line 5

def initialize(result)
  @result = result
  @src_files_list = nil
end

Instance Attribute Details

#src_files_listObject

Returns the value of attribute src_files_list.



3
4
5
# File 'lib/simplecov_covview/formatter.rb', line 3

def src_files_list
  @src_files_list
end

Instance Method Details

#formatterObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/simplecov_covview/formatter.rb', line 10

def formatter
  @src_files_list = @result.source_files.map do |file|
    contents = file.lines.map do |line|
      coverage = line.coverage.nil? ? "-" : "#{line.coverage}"
      {
        num: line.number,
        status: line.status,
        cov: coverage,
        src: line.src,
      }
    end

    result_file = SimplecovCovview::CovView::Resultfile.new(file)
    file_contents = { contents: contents }
    file_contents.merge(result_file.status)
  end

  self
end

#renderObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/simplecov_covview/formatter.rb', line 30

def render
  @src_files_list.each do |src_file|
    source_file = SimplecovCovview::CovView::Srcfile.new(src_file)
    puts source_file.header

    src_file[:contents].each do |line|
      row = SimplecovCovview::CovView::Srcfile::Line.new(line, src_file)
      puts row.colorize_contents
    end
  end
end