module Pluginscan class VulnerabilitiesPrinter < Printer def print(advisories, plugin_slug) raise ArgumentError, "Can't print a nil list of advisories" if advisories.nil? print_headline(advisories, plugin_slug) advisories.reverse.each do |advisory| print_advisory(advisory) end print_blank_line end private def print_headline(advisories, plugin_slug) if advisories.any? @output.puts "#{advisories.count} advisories were found for '#{plugin_slug}':".color(:blue) else @output.puts "No advisories were found for '#{plugin_slug}'".color(:blue) end end private def print_advisory(advisory) printer = VulnerabilityPrinter.new(@output) printer.print(advisory) end end class VulnerabilityPrinter < Printer def print(advisory) title = highlight_version_number(advisory.title) date = format_date(advisory.date) fixed = fixed_data(advisory.fixed_in) @output.puts " #{date} #{title} #{fixed}" @output.puts " #{advisory.url}" end private def highlight_version_number(title) version_number_regex = '([\<\>\=]+\ )?[\d\.]+' title.gsub( /(?#{version_number_regex})/, '\k'.color(:yellow) ) end private def format_date(date) date.strftime('%Y-%m-%d').color(:green) end private def fixed_data(fixed_version) return "(no fixed version!)".color(:red) if fixed_version.nil? "(fixed in #{fixed_version})".color(:red) end end end