class Covered::Statistics
def self.for(coverage)
def self.for(coverage) self.new.tap do |statistics| statistics << coverage end end
def << coverage
def << coverage @total << coverage (@paths[coverage.path] ||= coverage.empty).merge!(coverage) end
def [](path)
def [](path) @paths[path] end
def as_json
def as_json { total: total.as_json, paths: @paths.map{|path, coverage| [path, coverage.as_json]}.to_h, } end
def count
def count @paths.size end
def executable_count
def executable_count @total.executable_count end
def executed_count
def executed_count @total.executed_count end
def initialize
def initialize @total = Aggregate.new @paths = Hash.new end
def print(output)
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
def to_json(options)
def to_json(options) as_json.to_json(options) end
def validate!(minimum = 1.0)
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