Class: Covered::Statistics::Aggregate

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

Overview

Aggregate coverage totals.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Ratio

#complete?, #percentage, #ratio

Constructor Details

#initializeAggregate

Initialize empty aggregate statistics.



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

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

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



50
51
52
# File 'lib/covered/statistics.rb', line 50

def count
  @count
end

#executable_countObject (readonly)

The number of lines which could have been executed.



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

def executable_count
  @executable_count
end

#executed_countObject (readonly)

The number of lines that were executed.



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

def executed_count
  @executed_count
end

#The total number of coverage instances added.(totalnumberofcoverageinstancesadded.) ⇒ Object (readonly)



50
# File 'lib/covered/statistics.rb', line 50

attr :count

Class Method Details

.for(coverages) ⇒ Object

Build aggregate statistics from coverage objects.



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

def self.for(coverages)
	self.new.tap do |aggregate|
		coverages.each do |coverage|
			aggregate << coverage
		end
	end
end

Instance Method Details

#<<(coverage) ⇒ Object

Add coverage to these aggregate statistics.



81
82
83
84
85
86
87
88
# File 'lib/covered/statistics.rb', line 81

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

#as_jsonObject

A JSON-compatible representation of these aggregate statistics.



62
63
64
65
66
67
68
69
# File 'lib/covered/statistics.rb', line 62

def as_json
	{
		count: count,
		executable_count: executable_count,
		executed_count: executed_count,
		percentage: percentage.to_f.round(2),
	}
end

#to_json(options) ⇒ Object

Convert these aggregate statistics to JSON.



74
75
76
# File 'lib/covered/statistics.rb', line 74

def to_json(options)
	as_json.to_json(options)
end