Class: SvgConform::ConformanceReport
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- SvgConform::ConformanceReport
- Defined in:
- lib/svg_conform/conformance_report.rb
Overview
Main conformance report structure
Class Method Summary collapse
-
.from_svg_conform_result(filename, validation_result, profile: nil, use_svgcheck_mapping: false) ⇒ Object
Create report from SvgConform ValidationResult.
-
.from_svgcheck_result(filename, error_content, _output_content = nil) ⇒ Object
Create report from svgcheck error output.
-
.load_from_file(filepath) ⇒ Object
Load report from YAML file.
Instance Method Summary collapse
-
#compare_with(other_report) ⇒ Object
Compare two conformance reports.
-
#save_to_file(filepath) ⇒ Object
Save report to YAML file.
-
#valid? ⇒ Boolean
Check if the report indicates a valid SVG.
Class Method Details
.from_svg_conform_result(filename, validation_result, profile: nil, use_svgcheck_mapping: false) ⇒ Object
Create report from SvgConform ValidationResult
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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/svg_conform/conformance_report.rb', line 75 def self.from_svg_conform_result(filename, validation_result, profile: nil, use_svgcheck_mapping: false) report = new report.filename = filename report.profile = profile report.tool = "svg_conform" report.version = SvgConform::VERSION report. = Time.now.iso8601 report.valid = validation_result.valid? report.errors = IssueSummary.new report.errors.total_count = 0 report.errors.by_requirement = {} report.errors.issues = [] report.warnings = IssueSummary.new report.warnings.total_count = 0 report.warnings.by_requirement = {} report.warnings.issues = [] # Use SvgcheckCompatibilityEngine for svgcheck compatibility if use_svgcheck_mapping require_relative "external_checkers/svgcheck/compatibility_engine" compatibility_engine = ExternalCheckers::Svgcheck::CompatibilityEngine.new # Check if file should be treated as unparseable by svgcheck if compatibility_engine.should_mimic_parse_failure?(filename, validation_result) # Return empty report like svgcheck does for unparseable files return report end end # Process errors (including conditional validity_errors for svgcheck compatibility) all_errors = validation_result.errors.dup # For svgcheck compatibility: include validity_errors as regular errors if use_svgcheck_mapping && validation_result.validity_errors.any? compatibility_engine ||= ExternalCheckers::Svgcheck::CompatibilityEngine.new all_errors.concat(validation_result.validity_errors) if compatibility_engine.should_include_validity_errors?( validation_result, filename ) end if all_errors.any? # Filter errors using compatibility engine or use direct mapping filtered_errors = if use_svgcheck_mapping compatibility_engine ||= ExternalCheckers::Svgcheck::CompatibilityEngine.new compatibility_engine.filter_errors_for_svgcheck( all_errors, filename, validation_result ) else all_errors.map do |error| [error, error.requirement_id] end end error_groups = filtered_errors.group_by { |_error, req_id| req_id } error_groups.each do |req_id, error_pairs| report.errors.by_requirement[req_id] = error_pairs.length end # Update total count to reflect filtered errors report.errors.total_count = filtered_errors.length # Add ALL filtered errors (no sampling) report.errors.issues = filtered_errors.map do |error, mapped_req_id| # Extract attribute and value from error data if available attribute = error.data[:attribute] if error.respond_to?(:data) && error.data value = error.data[:value] if error.respond_to?(:data) && error.data issue = ConformanceIssue.new issue.type = "error" issue.requirement_id = mapped_req_id issue. = error. issue.element = error.element_name issue.attribute = attribute issue.value = value issue.line = error.line issue end end # Process warnings if validation_result.warnings.any? report.warnings.total_count = validation_result.warnings.length # Group by requirement_id warning_groups = validation_result.warnings.group_by(&:requirement_id) warning_groups.each do |req_id, warnings| report.warnings.by_requirement[req_id] = warnings.length end # Add ALL warnings (no sampling) report.warnings.issues = validation_result.warnings.map do |warning| issue = ConformanceIssue.new issue.type = "warning" issue.requirement_id = warning.requirement_id issue. = warning. issue.element = warning.element_name issue.line = warning.line issue end end report end |
.from_svgcheck_result(filename, error_content, _output_content = nil) ⇒ Object
Create report from svgcheck error output
184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 |
# File 'lib/svg_conform/conformance_report.rb', line 184 def self.from_svgcheck_result(filename, error_content, _output_content = nil) report = new report.filename = filename report.tool = "svgcheck" report. = Time.now.iso8601 report.valid = error_content.strip.empty? report.errors = IssueSummary.new report.errors.total_count = 0 report.errors.by_requirement = {} report.errors.issues = [] report.warnings = IssueSummary.new report.warnings.total_count = 0 report.warnings.by_requirement = {} report.warnings.issues = [] return report if error_content.strip.empty? # Parse svgcheck errors using the dedicated parser require_relative "external_checkers/svgcheck/parser" parser = ExternalCheckers::Svgcheck::Parser.new parsed_report = parser.parse(error_content, nil, filename: filename) errors = parsed_report.errors.issues if errors.any? report.errors.total_count = errors.length report.valid = false # Group by type for summary error_groups = errors.group_by { |e| e.requirement_id || "unknown" } error_groups.each do |type, type_errors| report.errors.by_requirement[type] = type_errors.length end # Add ALL errors (no sampling) report.errors.issues = errors end report end |
.load_from_file(filepath) ⇒ Object
Load report from YAML file
258 259 260 |
# File 'lib/svg_conform/conformance_report.rb', line 258 def self.load_from_file(filepath) from_yaml(File.read(filepath)) end |
Instance Method Details
#compare_with(other_report) ⇒ Object
Compare two conformance reports
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
# File 'lib/svg_conform/conformance_report.rb', line 227 def compare_with(other_report) differences = [] # Compare error counts differences << "Error count: #{errors.total_count} vs #{other_report.errors.total_count}" if errors.total_count != other_report.errors.total_count # Compare warning counts differences << "Warning count: #{warnings.total_count} vs #{other_report.warnings.total_count}" if warnings.total_count != other_report.warnings.total_count # Compare error types all_req_ids = (errors.by_requirement.keys + other_report.errors.by_requirement.keys).uniq all_req_ids.each do |req_id| our_count = errors.by_requirement[req_id] || 0 their_count = other_report.errors.by_requirement[req_id] || 0 differences << "#{req_id} errors: #{our_count} vs #{their_count}" if our_count != their_count end { identical: differences.empty?, differences: differences, summary: differences.empty? ? "Reports are identical" : "#{differences.length} differences found", } end |
#save_to_file(filepath) ⇒ Object
Save report to YAML file
253 254 255 |
# File 'lib/svg_conform/conformance_report.rb', line 253 def save_to_file(filepath) File.write(filepath, to_yaml) end |
#valid? ⇒ Boolean
Check if the report indicates a valid SVG
263 264 265 |
# File 'lib/svg_conform/conformance_report.rb', line 263 def valid? valid end |