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



88
89
90
# File 'lib/covered/statistics.rb', line 88

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

#as_jsonObject



92
93
94
95
96
97
# File 'lib/covered/statistics.rb', line 92

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


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

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



99
100
101
# File 'lib/covered/statistics.rb', line 99

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

#validate!(minimum = 1.0) ⇒ Object



124
125
126
127
128
# File 'lib/covered/statistics.rb', line 124

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