Class: CoverUp::FileResult

Inherits:
Object
  • Object
show all
Defined in:
lib/cover-up.rb

Overview

This tracks coverage results for an individual file

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, lines, hit, missed, excluded) ⇒ FileResult

This initializes the file result with the amount of lines, and the hit/missed/excluded lines for the file, along with the name



45
46
47
48
49
50
51
# File 'lib/cover-up.rb', line 45

def initialize(name, lines, hit, missed, excluded)
  self.name = name
  self.lines = lines
  self.hit = hit
  self.missed = missed
  self.excluded = excluded
end

Instance Attribute Details

#excludedObject

Returns the value of attribute excluded.



42
43
44
# File 'lib/cover-up.rb', line 42

def excluded
  @excluded
end

#hitObject

Returns the value of attribute hit.



42
43
44
# File 'lib/cover-up.rb', line 42

def hit
  @hit
end

#linesObject

Returns the value of attribute lines.



42
43
44
# File 'lib/cover-up.rb', line 42

def lines
  @lines
end

#missedObject

Returns the value of attribute missed.



42
43
44
# File 'lib/cover-up.rb', line 42

def missed
  @missed
end

#nameObject

Returns the value of attribute name.



42
43
44
# File 'lib/cover-up.rb', line 42

def name
  @name
end

Instance Method Details

#hit_percentageObject

This calculates the percentage of lines that were hit by the code being covered



59
60
61
62
# File 'lib/cover-up.rb', line 59

def hit_percentage
  return 0 if self.lines_with_exclusions.to_f == 0.0
  (self.hit.length.to_f / self.lines_with_exclusions.to_f) * 100.0
end

#lines_without_exclusionsObject

This returns the amount of lines after the excluded lines have been removed



54
55
56
# File 'lib/cover-up.rb', line 54

def lines_without_exclusions
  self.lines - excluded.length
end

#missed_percentageObject

This calculates the percentage of lines that were missed by the code being covered



65
66
67
68
# File 'lib/cover-up.rb', line 65

def missed_percentage
  return 0 if self.lines_with_exclusions.to_f == 0.0
  (self.missed.length.to_f / self.lines_with_exclusions.to_f) * 100.0
end