Class: DeepCover::Analyser::PerChar

Inherits:
DeepCover::Analyser show all
Defined in:
lib/deep_cover/analyser/per_char.rb

Instance Attribute Summary

Attributes included from Base

#options, #source

Instance Method Summary collapse

Methods included from OptionallyCovered

#optionally_covered

Methods included from IgnoreUncovered

#initialize, #node_runs

Methods included from Base

#covered_code, #each_node, #initialize, #node_children, #node_runs, #node_runs_map

Instance Method Details

#resultsObject

Returns an array of characters for each line of code. Each character is either ‘ ’ (executed), ‘-’ (not executable) or ‘x’ (not covered)



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/deep_cover/analyser/per_char.rb', line 7

def results
  buffer = covered_code.buffer
  bc = buffer.source_lines.map { |line| '-' * line.size }
  each_node do |node|
    runs = node_runs(node)
    next if runs == nil
    node.proper_range.each do |pos|
      bc[buffer.line_for_position(pos) - buffer.first_line][buffer.column_for_position(pos)] = runs > 0 ? ' ' : 'x'
    end
  end
  bc.zip(buffer.source_lines) { |cov, line| cov[line.size..-1] = '' } # remove extraneous character for end lines, in any
  bc
end