Module: Html2rss::CLI::Render
- Defined in:
- lib/html2rss/cli/render.rb
Overview
Text and JSON rendering for CLI command output (display only; no policy).
Constant Summary collapse
- VERDICT_COLORS =
ANSI colors for recon verdict labels in text output.
{ build: "\e[32m", defer: "\e[33m" }.freeze
Class Method Summary collapse
- .inspect_output(results, format:, batch_mode:) ⇒ void
- .json(data, batch_mode) ⇒ void
- .probe_card(view) ⇒ void
- .recon_output(results, format:, batch_mode:, url_only: false) ⇒ void
- .test_card(result, source) ⇒ void
Class Method Details
.inspect_output(results, format:, batch_mode:) ⇒ void
This method returns an undefined value.
20 21 22 23 24 25 26 |
# File 'lib/html2rss/cli/render.rb', line 20 def inspect_output(results, format:, batch_mode:) if format == 'json' json(results, batch_mode) else results.each { |data| probe_card(ProbeView.from_wire(data)) } end end |
.json(data, batch_mode) ⇒ void
This method returns an undefined value.
106 107 108 109 |
# File 'lib/html2rss/cli/render.rb', line 106 def json(data, batch_mode) payload = batch_mode ? data : data.first puts JSON.pretty_generate(payload) end |
.probe_card(view) ⇒ void
This method returns an undefined value.
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/html2rss/cli/render.rb', line 60 def probe_card(view) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity if view.verdict color = VERDICT_COLORS.fetch(view.verdict.to_sym, "\e[31m") puts "#{color}[#{view.verdict.to_s.upcase}]\e[0m #{view.requested}" else puts view.requested end probe_lines(view) if view.alternate_feeds.any? hrefs = view.alternate_feeds.filter_map { |f| ProbeView.wire_val(f, :href) } puts " Feeds: #{hrefs.join(', ')}" if hrefs.any? end puts " Feed: #{view.native_feed}" if view.native_feed puts " Notes: #{view.notes.join(', ')}" if view.notes.any? puts " Strategy: #{view.strategy}" if view.strategy puts '' end |
.recon_output(results, format:, batch_mode:, url_only: false) ⇒ void
This method returns an undefined value.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/html2rss/cli/render.rb', line 34 def recon_output(results, format:, batch_mode:, url_only: false) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity if url_only results.each { |r| puts r.requested_url } elsif format == 'json' json(results.map(&:to_h), batch_mode) elsif format == 'tsv' puts %w[verdict status requested_url final_url native_feed notes].join("\t") results.each do |r| row = [ r.verdict.to_s.upcase, r.status || '-', r.requested_url, r.final_url, r.native_feed || '-', r.notes.join('; ') ] puts row.join("\t") end else results.each { |r| probe_card(ProbeView.from_recon(r)) } end end |
.test_card(result, source) ⇒ void
This method returns an undefined value.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/html2rss/cli/render.rb', line 82 def test_card(result, source) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity if result.success puts "\e[32m✓ Schema valid\e[0m (#{source})" dur = "#{result.duration_seconds}s" puts "\e[32m✓ Extracted #{result.item_count} items in #{dur}\e[0m (strategy: #{result.strategy_used})" puts "\nChannel: #{result.channel_title} (#{result.channel_url})" if result.sample_items.any? puts 'Sample items:' result.sample_items.each_with_index do |item, i| puts " #{i + 1}. #{"#{item[:published_at]} | " if item[:published_at]}#{item[:title]}" puts " #{item[:url]}" end end else warn "\e[31m✗ Test failed\e[0m (#{source})" warn " Error: #{result.}" if result. result.validation_errors&.each { |k, v| warn " Schema error [#{k}]: #{Array(v).join(', ')}" } end end |