Class: Covered::Statistics

Inherits:
Wrapper show all
Includes:
Ratio
Defined in:
lib/covered/statistics.rb

Instance Attribute Summary collapse

Attributes inherited from Wrapper

#output

Instance Method Summary collapse

Methods included from Ratio

#complete?, #percentage, #ratio

Methods inherited from Wrapper

#accept?, #disable, #each, #enable, #expand_path, #flush, #mark, #relative_path, #to_h

Methods inherited from Base

#accept?, #disable, #each, #enable, #expand_path, #flush, #mark, #relative_path

Constructor Details

#initializeStatistics

Returns a new instance of Statistics.



29
30
31
32
33
# File 'lib/covered/statistics.rb', line 29

def initialize
	@count = 0
	@executable_count = 0
	@executed_count = 0
end

Instance Attribute Details

#countObject (readonly)

Total number of files added.



36
37
38
# File 'lib/covered/statistics.rb', line 36

def count
  @count
end

#executable_countObject (readonly)

The number of lines which could have been executed.



39
40
41
# File 'lib/covered/statistics.rb', line 39

def executable_count
  @executable_count
end

#executed_countObject (readonly)

The number of lines that were executed.



42
43
44
# File 'lib/covered/statistics.rb', line 42

def executed_count
  @executed_count
end

Instance Method Details

#<<(coverage) ⇒ Object



44
45
46
47
48
# File 'lib/covered/statistics.rb', line 44

def << coverage
	@count += 1
	@executable_count += coverage.executable_count
	@executed_count += coverage.executed_count
end


52
53
54
55
56
# File 'lib/covered/statistics.rb', line 52

def print(output)
	output.puts "* #{count} files checked; #{executed_count}/#{executable_count} lines executed; #{percentage.to_f.round(2)}% covered."
	
	# Could output funny message here, especially for 100% coverage.
end

#validate!(minimum = 1.0) ⇒ Object



58
59
60
61
62
# File 'lib/covered/statistics.rb', line 58

def validate!(minimum = 1.0)
	if self.ratio < minimum
		raise CoverageError, "Coverage of #{self.percentage.to_f.round(2)}% is less than required minimum of #{(minimum * 100.0).round(2)}%!"
	end
end