class Covered::Files::State
def self.for(path, **options)
def self.for(path, **options) self.new(Source.new(path, **options)) end
def [](lineno)
def [](lineno) @counts[lineno] end
def annotate(lineno, annotation)
def annotate(lineno, annotation) @annotations[lineno] ||= [] @annotations[lineno] << annotation end
def coverage
def coverage Coverage.new(@source, @counts, @annotations) end
def initialize(source)
def initialize(source) @source = source @counts = [] @annotations = {} end
def mark(lineno, value = 1)
def mark(lineno, value = 1) # As currently implemented, @counts is base-zero rather than base-one. # Line numbers generally start at line 1, so the first line, line 1, is at index 1. This means that index[0] is usually nil. Array(value).each_with_index do |value, index| offset = lineno + index if @counts[offset] @counts[offset] += value else @counts[offset] = value end end end
def merge!(coverage)
def merge!(coverage) coverage.counts.each_with_index do |count, index| if count @counts[index] ||= 0 @counts[index] += count end end @annotations.merge!(coverage.annotations) do |lineno, a, b| Array(a) + Array(b) end end