Class: Covered::Statistics
- Inherits:
-
Object
- Object
- Covered::Statistics
show all
- Includes:
- Ratio
- Defined in:
- lib/covered/statistics.rb
Defined Under Namespace
Classes: Aggregate
Constant Summary
collapse
- COMPLETE =
[
"Enter the code dojo: 100% coverage attained, bugs defeated with one swift strike.",
"Nirvana reached: 100% code coverage, where bugs meditate and vanish like a passing cloud.",
"With 100% coverage, your code has unlocked the path to enlightenment – bugs have no place to hide.",
"In the realm of code serenity, 100% coverage is your ticket to coding enlightenment.",
"100% coverage, where code and bugs coexist in perfect harmony, like Yin and Yang.",
"Achieving the Zen of code coverage, your code is a peaceful garden where bugs find no shelter.",
"Congratulations on coding enlightenment! 100% coverage means your code is one with the universe.",
"With 100% coverage, your code is a tranquil pond where bugs cause no ripples.",
"At the peak of code mastery: 100% coverage, where bugs bow down before the wisdom of your code.",
"100% code coverage: Zen achieved! Bugs in harmony, code at peace.",
]
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Ratio
#complete?, #percentage, #ratio
Constructor Details
Returns a new instance of Statistics.
61
62
63
64
|
# File 'lib/covered/statistics.rb', line 61
def initialize
@total = Aggregate.new
@paths = Hash.new
end
|
Instance Attribute Details
#total ⇒ Object
Returns the value of attribute total.
83
84
85
|
# File 'lib/covered/statistics.rb', line 83
def total
@total
end
|
Class Method Details
.for(coverage) ⇒ Object
16
17
18
19
20
|
# File 'lib/covered/statistics.rb', line 16
def self.for(coverage)
self.new.tap do |statistics|
statistics << coverage
end
end
|
Instance Method Details
#<<(coverage) ⇒ Object
78
79
80
81
|
# File 'lib/covered/statistics.rb', line 78
def << coverage
@total << coverage
(@paths[coverage.path] ||= coverage.empty).merge!(coverage)
end
|
#[](path) ⇒ Object
85
86
87
|
# File 'lib/covered/statistics.rb', line 85
def [](path)
@paths[path]
end
|
#as_json ⇒ Object
89
90
91
92
93
94
|
# File 'lib/covered/statistics.rb', line 89
def as_json
{
total: total.as_json,
paths: @paths.map{|path, coverage| [path, coverage.as_json]}.to_h,
}
end
|
#count ⇒ Object
66
67
68
|
# File 'lib/covered/statistics.rb', line 66
def count
@paths.size
end
|
#executable_count ⇒ Object
70
71
72
|
# File 'lib/covered/statistics.rb', line 70
def executable_count
@total.executable_count
end
|
#executed_count ⇒ Object
74
75
76
|
# File 'lib/covered/statistics.rb', line 74
def executed_count
@total.executed_count
end
|
#print(output) ⇒ Object
113
114
115
116
117
118
119
|
# File 'lib/covered/statistics.rb', line 113
def print(output)
output.puts "#{count} files checked; #{@total.executed_count}/#{@total.executable_count} lines executed; #{@total.percentage.to_f.round(2)}% covered."
if self.complete?
output.puts "🧘 #{COMPLETE.sample}"
end
end
|
#to_json(options) ⇒ Object
96
97
98
|
# File 'lib/covered/statistics.rb', line 96
def to_json(options)
as_json.to_json(options)
end
|
#validate!(minimum = 1.0) ⇒ Object
121
122
123
124
125
|
# File 'lib/covered/statistics.rb', line 121
def validate!(minimum = 1.0)
if total.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
|