HTML
end
private
# rubocop:disable Metrics/MethodLength
# rubocop:disable Metrics/AbcSize
def body
html = [""]
@coverage[:source_files].each do |source_file|
percentage = source_file[:covered_percent].round(2)
bg_color = percentage_bar_color(percentage)
html << "
"
html << "
"
html << "
"
html << "
"
html << "
"
html << "
"
html << "
"
html << "
#{percentage}%
"
html << "
#{source_file[:name]}
"
html << "
#{not_covered_lines(source_file)}
"
html << "
"
end
html << ""
html.join("\n ")
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/MethodLength
def percentage_bar_color(percentage)
if percentage < 33.33
"bg-danger"
elsif percentage < 66.66
"bg-warning"
else
"bg-success"
end
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
end