Class: Covered::Coverage

Inherits:
Object
  • Object
show all
Includes:
Ratio
Defined in:
lib/covered/coverage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Ratio

#complete?, #percentage, #ratio

Constructor Details

#initialize(path, counts = []) ⇒ Coverage

Returns a new instance of Coverage.



39
40
41
42
43
44
45
# File 'lib/covered/coverage.rb', line 39

def initialize(path, counts = [])
	@path = path
	@counts = counts
	
	@executable_lines = nil
	@executed_lines = nil
end

Instance Attribute Details

#countsObject (readonly)

Returns the value of attribute counts.



48
49
50
# File 'lib/covered/coverage.rb', line 48

def counts
  @counts
end

#pathObject (readonly)

Returns the value of attribute path.



47
48
49
# File 'lib/covered/coverage.rb', line 47

def path
  @path
end

Instance Method Details

#[](lineno) ⇒ Object



60
61
62
# File 'lib/covered/coverage.rb', line 60

def [] lineno
	@counts[lineno]
end

#executable_countObject



76
77
78
# File 'lib/covered/coverage.rb', line 76

def executable_count
	executable_lines.count
end

#executable_linesObject



72
73
74
# File 'lib/covered/coverage.rb', line 72

def executable_lines
	@executable_lines ||= @counts.compact
end

#executed_countObject



84
85
86
# File 'lib/covered/coverage.rb', line 84

def executed_count
	executed_lines.count
end

#executed_linesObject



80
81
82
# File 'lib/covered/coverage.rb', line 80

def executed_lines
	@executed_lines ||= executable_lines.reject(&:zero?)
end

#freezeObject



50
51
52
53
54
55
56
57
58
# File 'lib/covered/coverage.rb', line 50

def freeze
	return if frozen?
	
	@counts.freeze
	executable_lines
	executed_lines
	
	super
end

#mark(lineno, value = 1) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/covered/coverage.rb', line 64

def mark(lineno, value = 1)
	if @counts[lineno]
		@counts[lineno] += value
	else
		@counts[lineno] = value
	end
end


90
91
92
# File 'lib/covered/coverage.rb', line 90

def print_summary(output)
	output.puts "** #{executed_count}/#{executable_count} lines executed; #{percentage.to_f.round(2)}% covered."
end