Class: Covered::Statistics

Inherits:
Object
  • Object
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

#initializeStatistics

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

#pathsObject (readonly)

Returns the value of attribute paths.



67
68
69
# File 'lib/covered/statistics.rb', line 67

def paths
  @paths
end

#totalObject (readonly)

Returns the value of attribute total.



66
67
68
# File 'lib/covered/statistics.rb', line 66

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



81
82
83
84
# File 'lib/covered/statistics.rb', line 81

def << coverage
	@total << coverage
	(@paths[coverage.path] ||= coverage.empty).merge!(coverage)
end

#[](path) ⇒ Object



86
87
88
# File 'lib/covered/statistics.rb', line 86

def [](path)
	@paths[path]
end

#as_jsonObject



90
91
92
93
94
95
# File 'lib/covered/statistics.rb', line 90

def as_json
	{
		total: total.as_json,
		paths: @paths.map{|path, coverage| [path, coverage.as_json]}.to_h,
	}
end

#countObject



69
70
71
# File 'lib/covered/statistics.rb', line 69

def count
	@paths.size
end

#executable_countObject



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

def executable_count
	@total.executable_count
end

#executed_countObject



77
78
79
# File 'lib/covered/statistics.rb', line 77

def executed_count
	@total.executed_count
end


114
115
116
117
118
119
120
# File 'lib/covered/statistics.rb', line 114

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



97
98
99
# File 'lib/covered/statistics.rb', line 97

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

#validate!(minimum = 1.0) ⇒ Object



122
123
124
125
126
# File 'lib/covered/statistics.rb', line 122

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