Module: DeepCover::Tools::FormatCharCover
- Defined in:
- lib/deep_cover/tools/format_char_cover.rb
Constant Summary collapse
- COLOR =
{'x' => :red, ' ' => :green, '-' => :faint}.freeze
- WHITESPACE_MAP =
Hash.new { |_, v| v }.merge!(' ' => '·', "\t" => '→ ')
Instance Method Summary collapse
Instance Method Details
#format_char_cover(covered_code, show_whitespace: false, **options) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/deep_cover/tools/format_char_cover.rb', line 7 def format_char_cover(covered_code, show_whitespace: false, **) bc = covered_code.char_cover(**) covered_code.buffer.source_lines.map.with_index do |line, line_index| next line if line.strip =~ /^#[ >]/ line.chars.map.with_index do |c, c_index| color = COLOR[bc[line_index][c_index]] c = WHITESPACE_MAP[c] if show_whitespace Term::ANSIColor.send(color, c) end.join end end |