Sha256: fb617c14b80ce3cd82f6a9d9e3e5b9e354f162e69b5cc78604e1328750f513ce

Contents?: true

Size: 1.13 KB

Versions: 12

Compression:

Stored size: 1.13 KB

Contents

# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2018-2022, by Samuel Williams.

require_relative 'wrapper'
require_relative 'coverage'

module Covered
	class CoverageError < StandardError
	end
	
	class Statistics < Wrapper
		def initialize
			@count = 0
			@executable_count = 0
			@executed_count = 0
		end
		
		# Total number of files added.
		attr :count
		
		# The number of lines which could have been executed.
		attr :executable_count
		
		# The number of lines that were executed.
		attr :executed_count
		
		def << coverage
			@count += 1
			@executable_count += coverage.executable_count
			@executed_count += coverage.executed_count
		end
		
		include Ratio
		
		def print(output)
			output.puts "* #{count} files checked; #{executed_count}/#{executable_count} lines executed; #{percentage.to_f.round(2)}% covered."
			
			# Could output funny message here, especially for 100% coverage.
		end
		
		def validate!(minimum = 1.0)
			if self.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
	end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
covered-0.19.1 lib/covered/statistics.rb
covered-0.19.0 lib/covered/statistics.rb
covered-0.18.5 lib/covered/statistics.rb
covered-0.18.4 lib/covered/statistics.rb
covered-0.18.3 lib/covered/statistics.rb
covered-0.18.2 lib/covered/statistics.rb
covered-0.18.1 lib/covered/statistics.rb
covered-0.18.0 lib/covered/statistics.rb
covered-0.17.1 lib/covered/statistics.rb
covered-0.17.0 lib/covered/statistics.rb
covered-0.16.9 lib/covered/statistics.rb
covered-0.16.8 lib/covered/statistics.rb