Class: CoverMe::Index

Inherits:
Object
  • Object
show all
Defined in:
lib/cover_me/index.rb

Overview

Used to generate an index page for the code coverage.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reports = []) ⇒ Index

:nodoc:



5
6
7
# File 'lib/cover_me/index.rb', line 5

def initialize(reports = []) # :nodoc:
  self.reports = reports
end

Instance Attribute Details

#reportsObject

Returns the value of attribute reports.



3
4
5
# File 'lib/cover_me/index.rb', line 3

def reports
  @reports
end

Instance Method Details

#percent_testedObject

Returns an average percent across all files.



34
35
36
37
38
39
40
# File 'lib/cover_me/index.rb', line 34

def percent_tested
  unless @percent_tested
    @percent_tested = (total_loc - total_untested_loc).to_f / (total_loc).to_f * 100
    @percent_tested = (@percent_tested.nan? ? 0 : @percent_tested.round(2))
  end
  return @percent_tested
end

#total_linesObject

Returns the total number of lines across all files.



10
11
12
13
14
15
# File 'lib/cover_me/index.rb', line 10

def total_lines
  unless @total_lines
    @total_lines = self.reports.inject(0) {|sum, x| sum += x.lines; sum}
  end
  return @total_lines
end

#total_locObject

Returns the total number of lines of code across all files.



18
19
20
21
22
23
# File 'lib/cover_me/index.rb', line 18

def total_loc
  unless @total_loc
    @total_loc = self.reports.inject(0) {|sum, x| sum += x.lines_of_code; sum}
  end
  return @total_loc
end

#total_untested_locObject

Returns the total number of untested lines of code across all files.



26
27
28
29
30
31
# File 'lib/cover_me/index.rb', line 26

def total_untested_loc
  unless @total_untested_loc
    @total_untested_loc = self.reports.inject(0) {|sum, x| sum += (x.lines_of_code - x.lines_executed); sum}
  end
  return @total_untested_loc
end