require "json" class Couve::Parser def initialize(coverage) @coverage = JSON.parse(coverage, symbolize_names: true) @coverage[:source_files].reject! { |file| file[:covered_percent] == 100 } @coverage[:source_files].sort_by! { |file| file[:covered_percent] } end def to_html <<~HTML

Coverage problems

#{body}
Coverage File Not covered lines
HTML end private def body html = [""] @coverage[:source_files].each do |source_file| html << " " html << " #{source_file[:covered_percent].round(2)}%" html << " #{source_file[:name]}" html << " #{not_covered_lines(source_file)}" html << " " end html << "" html.join("\n ") end def not_covered_lines(source_file) total_lines = JSON.parse(source_file[:coverage]) not_covered = total_lines.each_with_index.map do |line, index| next if line != 0 index + 1 end not_covered.compact.join(", ") end end