module Pluginscan # Responsible for printing a check description and all of the # findings associated with that check class CheckFindingsPrinter < Printer def print(check, findings) return if findings.empty? && check.name != 'Encoding' # Encoding deliberately has no findings because its a file-level check. TODO: Find a better way to handle this. The benefits of filtering out findings before we try and print them are significant. @output.puts CheckView.new(check).title_line print_findings(findings) print_blank_line end private def print_findings(findings) printer = FindingPrinter.new(@output) findings.each do |finding| printer.print(finding) end end end # Decorate Check with view-specific methods class CheckView < SimpleDelegator def initialize(check) @check = check super end def title_line name = "#{@check.name}:".color(:red) message = @check.message.color(:yellow) " #{name} #{message}" end end end