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
46
47
48
# File 'lib/covered/coverage.rb', line 39

def initialize(path, counts = [])
	@path = path
	@counts = counts
	@total = 0
	
	@annotations = {}
	
	@executable_lines = nil
	@executed_lines = nil
end

Instance Attribute Details

#annotationsObject (readonly)

Returns the value of attribute annotations


54
55
56
# File 'lib/covered/coverage.rb', line 54

def annotations
  @annotations
end

#countsObject (readonly)

Returns the value of attribute counts


51
52
53
# File 'lib/covered/coverage.rb', line 51

def counts
  @counts
end

#pathObject (readonly)

Returns the value of attribute path


50
51
52
# File 'lib/covered/coverage.rb', line 50

def path
  @path
end

#totalObject (readonly)

Returns the value of attribute total


52
53
54
# File 'lib/covered/coverage.rb', line 52

def total
  @total
end

Instance Method Details

#[](lineno) ⇒ Object


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

def [] lineno
	@counts[lineno]
end

#annotate(lineno, annotation) ⇒ Object


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

def annotate(lineno, annotation)
	@annotations[lineno] ||= []
	@annotations[lineno] << annotation
end

#executable_countObject


107
108
109
# File 'lib/covered/coverage.rb', line 107

def executable_count
	executable_lines.count
end

#executable_linesObject


103
104
105
# File 'lib/covered/coverage.rb', line 103

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

#executed_countObject


115
116
117
# File 'lib/covered/coverage.rb', line 115

def executed_count
	executed_lines.count
end

#executed_linesObject


111
112
113
# File 'lib/covered/coverage.rb', line 111

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

#freezeObject


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

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

#mark(lineno, value = 1) ⇒ Object


93
94
95
96
97
98
99
100
101
# File 'lib/covered/coverage.rb', line 93

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

#missing_countObject


119
120
121
# File 'lib/covered/coverage.rb', line 119

def missing_count
	executable_count - executed_count
end

125
126
127
# File 'lib/covered/coverage.rb', line 125

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

#read(&block) ⇒ Object


56
57
58
59
60
61
62
# File 'lib/covered/coverage.rb', line 56

def read(&block)
	if block_given?
		File.open(@path, "r", &block)
	else
		File.read(@path)
	end
end

#to_aObject


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

def to_a
	@counts
end

#to_sObject


129
130
131
# File 'lib/covered/coverage.rb', line 129

def to_s
	"\#<#{self.class} path=#{@path} #{percentage.to_f.round(2)}% covered>"
end

#zero?Boolean

Returns:

  • (Boolean)

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

def zero?
	@total.zero?
end