class Aggregate
Aggregate coverage totals.
Definitions
def self.for(coverages)
Build aggregate statistics from coverage objects.
Signature
-
parameter
coveragesEnumerable(Covered::Coverage) The coverage objects to summarize.
-
returns
Covered::Statistics::Aggregate The aggregate statistics.
Implementation
def self.for(coverages)
self.new.tap do |aggregate|
coverages.each do |coverage|
aggregate << coverage
end
end
end
def initialize
Initialize empty aggregate statistics.
Implementation
def initialize
@count = 0
@executable_count = 0
@executed_count = 0
end
attr :count
Signature
-
attribute
Integer The total number of coverage instances added.
attr :executable_count
The number of lines which could have been executed.
Signature
-
returns
Integer The executable line count.
attr :executed_count
The number of lines that were executed.
Signature
-
returns
Integer The executed line count.
def as_json
A JSON-compatible representation of these aggregate statistics.
Signature
-
returns
Hash The aggregate count, line counts and percentage.
Implementation
def as_json
{
count: count,
executable_count: executable_count,
executed_count: executed_count,
percentage: percentage.to_f.round(2),
}
end
def to_json(options)
Convert these aggregate statistics to JSON.
Signature
-
parameter
optionsHash Options forwarded to
to_json.-
returns
String The JSON representation.
Implementation
def to_json(options)
as_json.to_json(options)
end
def <<(coverage)
Add coverage to these aggregate statistics.
Signature
-
parameter
coverageCovered::Coverage The coverage object to add.
-
returns
Covered::Statistics::Aggregate This aggregate.
Implementation
def << coverage
@count += 1
@executable_count += coverage.executable_count
@executed_count += coverage.executed_count
self
end