Class: SvgConform::SvgQualityReport

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/svg_conform/quality_report.rb

Overview

Represents a single SVG file's quality analysis report. Uses lutaml-model for YAML serialization and supports terminal rendering.

Examples:

YAML output

report = analyzer.analyze_file('image.svg')
puts report.to_yaml

Terminal rendering

puts report.render  # Colorful terminal output with emojis

Instance Method Summary collapse

Instance Method Details

#render(theme: TerminalTheme.default) ⇒ String

Render report as colorful terminal output

Parameters:

  • (defaults to: TerminalTheme.default)

    Theme configuration for colors/emojis

Returns:

  • ANSI-colored terminal output



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/svg_conform/quality_report.rb', line 66

def render(theme: TerminalTheme.default)
  lines = []

  # Header with level emoji
  lines << theme.header("📊 SVG Quality Report: #{File.basename(file_path)}")
  lines << ""

  # Quality score with color
  lines << "  #{theme.level_emoji(quality_level)} Quality: #{theme.wrap_with_level(
    quality_score.to_s, quality_level
  )} (#{theme.level_name(quality_level)})"

  # Content health
  health_emoji = health_emoji_for(content_health)
  lines << "  #{health_emoji} Content Health: #{content_health}"

  # File info
  lines << ""
  lines << "  📁 File: #{file_size_kb.round(2)} KB (#{size_category})"
  lines << "  📐 Elements: #{element_count}"
  lines << "  🔢 Complexity: #{complexity_index.round(1)}/10"

  # Errors breakdown
  lines << ""
  lines << theme.separator("Errors: #{error_count}")
  lines << "  🔧 Remediable: #{theme.wrap_with_severity(
    remediable_errors.to_s, :remediable
  )}"
  lines << "  ⚠️  Non-remediable: #{theme.wrap_with_severity(
    non_remediable_errors.to_s, :non_remediable
  )}"

  if error_count.positive?
    lines << ""
    lines << "  Breakdown:"
    if critical_errors.positive?
      lines << "    #{theme.wrap_with_severity(
        "● Critical: #{critical_errors}", :critical
      )}"
    end
    if high_errors.positive?
      lines << "    #{theme.wrap_with_severity("● High: #{high_errors}",
                                               :high)}"
    end
    if medium_errors.positive?
      lines << "    #{theme.wrap_with_severity("● Medium: #{medium_errors}",
                                               :medium)}"
    end
    if low_errors.positive?
      lines << "    #{theme.wrap_with_severity("● Low: #{low_errors}",
                                               :low)}"
    end
  end

  # Features
  features = []
  features << "Base64" if has_base64
  features << "Foreign NS" if has_foreign_ns
  features << "Masks" if has_masks
  features << "ClipPaths" if has_clip_paths
  features << "External Refs" if has_external_refs

  if features.any?
    lines << ""
    lines << "  ✨ Features: #{features.join(', ')}"
  end

  lines << ""
  lines.join("\n")
end