Sha256: 13c32de74f715f202e09c979b7100a4dfbd11ee21eaee84b319a53b907f272e5

Contents?: true

Size: 658 Bytes

Versions: 13

Compression:

Stored size: 658 Bytes

Contents

module DeepCover
  module Tools::FormatCharCover
    COLOR = {'x' => :red, ' ' => :green, '-' => :faint}
    WHITESPACE_MAP = Hash.new{|_, v| v}.merge!(' ' => '·', "\t" => '→ ')
    def format_char_cover(covered_code, show_whitespace: false, **options)
      bc = covered_code.char_cover(**options)
      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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
deep-cover-0.1.14 lib/deep_cover/tools/format_char_cover.rb
deep-cover-0.1.13 lib/deep_cover/tools/format_char_cover.rb
deep-cover-0.1.12 lib/deep_cover/tools/format_char_cover.rb
deep-cover-0.1.11 lib/deep_cover/tools/format_char_cover.rb
deep-cover-0.1.10 lib/deep_cover/tools/format_char_cover.rb
deep-cover-0.1.9 lib/deep_cover/tools/format_char_cover.rb
deep-cover-0.1.8 lib/deep_cover/tools/format_char_cover.rb
deep-cover-0.1.7 lib/deep_cover/tools/format_char_cover.rb
deep-cover-0.1.6 lib/deep_cover/tools/format_char_cover.rb
deep-cover-0.1.5 lib/deep_cover/tools/format_char_cover.rb
deep-cover-0.1.4 lib/deep_cover/tools/format_char_cover.rb
deep-cover-0.1.3 lib/deep_cover/tools/format_char_cover.rb
deep-cover-0.1.2 lib/deep_cover/tools/format_char_cover.rb