# frozen_string_literal: true module BrokenLinkFinder # Class responsible for reporting in a HTML format. class HTMLReporter < Reporter # Returns a new HTMLReporter instance. # stream is any Object that responds to :puts and :print. def initialize(stream, sort, broken_links, ignored_links, broken_link_map, crawl_stats) super end # Pretty print a report detailing the full link summary. def call(broken_verbose: true, ignored_verbose: false) puts '' nil end private # Report a summary of the overall crawl. def report_crawl_summary puts format( '

Crawled %s
%s page(s) containing %s unique link(s) in %s seconds

', @crawl_stats[:url], @crawl_stats[:url], @crawl_stats[:num_pages], @crawl_stats[:num_links], @crawl_stats[:duration]&.truncate(2) ) end # Report a summary of the broken links. def report_broken_links(verbose: true) puts '' end # Report a summary of the ignored links. def report_ignored_links(verbose: false) puts '' end def puts_summary(text, type:) klass = (type == :broken) ? 'broken_links_summary' : 'ignored_links_summary' puts "

#{text}

" end def puts_group(link, type:) href = build_url(link) a_element = "#{link}" case type when :broken msg = sort_by_page? ? "The following broken links were found on '#{a_element}':" : "The broken link '#{a_element}' was found on the following pages:" klass = 'broken_links_group' when :ignored msg = sort_by_page? ? "The following links were ignored on '#{a_element}':" : "The link '#{a_element}' was ignored on the following pages:" klass = 'ignored_links_group' else raise "type: must be :broken or :ignored, not: #{type}" end puts "

" puts msg + '
' end def puts_group_item(value, type:) klass = (type == :broken) ? 'broken_links_group_item' : 'ignored_links_group_item' puts "#{value}
" end def build_url(link) href = @broken_link_map[link] href || link end alias_method :report, :call end end