Class: Fontisan::Models::ValidationReport
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Fontisan::Models::ValidationReport
- Defined in:
- lib/fontisan/models/validation_report.rb
Overview
ValidationReport represents the result of font validation
This model encapsulates all validation results including error, warning, and informational messages. It supports serialization to YAML, JSON, and plain text formats for different use cases.
Defined Under Namespace
Classes: CheckResult, Issue, Summary
Instance Method Summary collapse
-
#add_error(category, message, location = nil) ⇒ void
Add an error to the report.
-
#add_info(category, message, location = nil) ⇒ void
Add an info message to the report.
-
#add_warning(category, message, location = nil) ⇒ void
Add a warning to the report.
-
#checks_by_status(passed:) ⇒ Array<CheckResult>
Get checks by status.
-
#errors ⇒ Array<Issue>
Get all error issues.
-
#errors_only ⇒ Array<Issue>
Get error issues only.
-
#failed_check_ids ⇒ Array<String>
Get IDs of failed checks.
-
#failed_checks ⇒ Array<CheckResult>
Get all failed checks.
-
#failure_rate ⇒ Float
Calculate failure rate as percentage.
-
#fatal_errors ⇒ Array<Issue>
Get fatal error issues.
-
#field_issues(table_tag, field_name) ⇒ Array<CheckResult>
Get check results for a specific field in a table.
-
#has_errors? ⇒ Boolean
Check if report has errors.
-
#has_warnings? ⇒ Boolean
Check if report has warnings.
-
#info_issues ⇒ Array<Issue>
Get all info issues.
-
#info_only ⇒ Array<Issue>
Get info issues only.
-
#issues_by_category(category) ⇒ Array<Issue>
Get issues by category.
-
#issues_by_severity(severity) ⇒ Array<Issue>
Get issues by severity level.
-
#pass_rate ⇒ Float
Calculate pass rate as percentage.
-
#passed? ⇒ Boolean
Check if font passed validation (alias for valid).
-
#passed_check_ids ⇒ Array<String>
Get IDs of passed checks.
-
#passed_checks ⇒ Array<CheckResult>
Get all passed checks.
-
#result_of(check_id) ⇒ CheckResult?
Get result for a specific check by ID.
-
#severity_distribution ⇒ Hash
Get severity distribution.
-
#table_issues(table_tag) ⇒ Array<CheckResult>
Get check results for a specific table.
-
#text_summary ⇒ String
Get a text summary of the validation.
-
#to_summary ⇒ String
Generate brief summary.
-
#to_table_format ⇒ String
Generate tabular format for CLI.
-
#to_text_report ⇒ String
Generate full detailed text report.
-
#valid? ⇒ Boolean
Check if font is valid (alias for valid attribute).
-
#warnings ⇒ Array<Issue>
Get all warning issues.
-
#warnings_only ⇒ Array<Issue>
Get warning issues only.
Instance Method Details
#add_error(category, message, location = nil) ⇒ void
This method returns an undefined value.
Add an error to the report
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/fontisan/models/validation_report.rb', line 136 def add_error(category, , location = nil) issues << Issue.new( severity: "error", category: category, message: , location: location, ) summary.errors += 1 self.valid = false end |
#add_info(category, message, location = nil) ⇒ void
This method returns an undefined value.
Add an info message to the report
169 170 171 172 173 174 175 176 177 |
# File 'lib/fontisan/models/validation_report.rb', line 169 def add_info(category, , location = nil) issues << Issue.new( severity: "info", category: category, message: , location: location, ) summary.info += 1 end |
#add_warning(category, message, location = nil) ⇒ void
This method returns an undefined value.
Add a warning to the report
153 154 155 156 157 158 159 160 161 |
# File 'lib/fontisan/models/validation_report.rb', line 153 def add_warning(category, , location = nil) issues << Issue.new( severity: "warning", category: category, message: , location: location, ) summary.warnings += 1 end |
#checks_by_status(passed:) ⇒ Array<CheckResult>
Get checks by status
352 353 354 |
# File 'lib/fontisan/models/validation_report.rb', line 352 def checks_by_status(passed:) check_results.select { |cr| cr.passed == passed } end |
#errors ⇒ Array<Issue>
Get all error issues
182 183 184 |
# File 'lib/fontisan/models/validation_report.rb', line 182 def errors issues.select { |issue| issue.severity == "error" } end |
#errors_only ⇒ Array<Issue>
Get error issues only
301 302 303 |
# File 'lib/fontisan/models/validation_report.rb', line 301 def errors_only issues_by_severity(:error) end |
#failed_check_ids ⇒ Array<String>
Get IDs of failed checks
359 360 361 |
# File 'lib/fontisan/models/validation_report.rb', line 359 def failed_check_ids failed_checks.map(&:check_id) end |
#failed_checks ⇒ Array<CheckResult>
Get all failed checks
277 278 279 |
# File 'lib/fontisan/models/validation_report.rb', line 277 def failed_checks check_results.reject(&:passed) end |
#failure_rate ⇒ Float
Calculate failure rate as percentage
375 376 377 378 |
# File 'lib/fontisan/models/validation_report.rb', line 375 def failure_rate return 0.0 if check_results.empty? failed_checks.length.to_f / check_results.length end |
#fatal_errors ⇒ Array<Issue>
Get fatal error issues
294 295 296 |
# File 'lib/fontisan/models/validation_report.rb', line 294 def fatal_errors issues_by_severity(:fatal) end |
#field_issues(table_tag, field_name) ⇒ Array<CheckResult>
Get check results for a specific field in a table
342 343 344 |
# File 'lib/fontisan/models/validation_report.rb', line 342 def field_issues(table_tag, field_name) check_results.select { |cr| cr.table == table_tag.to_s && cr.field == field_name.to_s } end |
#has_errors? ⇒ Boolean
Check if report has errors
203 204 205 |
# File 'lib/fontisan/models/validation_report.rb', line 203 def has_errors? summary.errors.positive? end |
#has_warnings? ⇒ Boolean
Check if report has warnings
210 211 212 |
# File 'lib/fontisan/models/validation_report.rb', line 210 def has_warnings? summary.warnings.positive? end |
#info_issues ⇒ Array<Issue>
Get all info issues
196 197 198 |
# File 'lib/fontisan/models/validation_report.rb', line 196 def info_issues issues.select { |issue| issue.severity == "info" } end |
#info_only ⇒ Array<Issue>
Get info issues only
315 316 317 |
# File 'lib/fontisan/models/validation_report.rb', line 315 def info_only issues_by_severity(:info) end |
#issues_by_category(category) ⇒ Array<Issue>
Get issues by category
325 326 327 |
# File 'lib/fontisan/models/validation_report.rb', line 325 def issues_by_category(category) issues.select { |issue| issue.category == category.to_s } end |
#issues_by_severity(severity) ⇒ Array<Issue>
Get issues by severity level
287 288 289 |
# File 'lib/fontisan/models/validation_report.rb', line 287 def issues_by_severity(severity) issues.select { |issue| issue.severity == severity.to_s } end |
#pass_rate ⇒ Float
Calculate pass rate as percentage
383 384 385 |
# File 'lib/fontisan/models/validation_report.rb', line 383 def pass_rate 1.0 - failure_rate end |
#passed? ⇒ Boolean
Check if font passed validation (alias for valid)
248 249 250 |
# File 'lib/fontisan/models/validation_report.rb', line 248 def passed? valid end |
#passed_check_ids ⇒ Array<String>
Get IDs of passed checks
366 367 368 |
# File 'lib/fontisan/models/validation_report.rb', line 366 def passed_check_ids passed_checks.map(&:check_id) end |
#passed_checks ⇒ Array<CheckResult>
Get all passed checks
270 271 272 |
# File 'lib/fontisan/models/validation_report.rb', line 270 def passed_checks check_results.select(&:passed) end |
#result_of(check_id) ⇒ CheckResult?
Get result for a specific check by ID
263 264 265 |
# File 'lib/fontisan/models/validation_report.rb', line 263 def result_of(check_id) check_results.find { |cr| cr.check_id == check_id.to_s } end |
#severity_distribution ⇒ Hash
Get severity distribution
390 391 392 393 394 395 396 |
# File 'lib/fontisan/models/validation_report.rb', line 390 def severity_distribution { errors: summary.errors, warnings: summary.warnings, info: summary.info, } end |
#table_issues(table_tag) ⇒ Array<CheckResult>
Get check results for a specific table
333 334 335 |
# File 'lib/fontisan/models/validation_report.rb', line 333 def table_issues(table_tag) check_results.select { |cr| cr.table == table_tag.to_s } end |
#text_summary ⇒ String
Get a text summary of the validation
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
# File 'lib/fontisan/models/validation_report.rb', line 217 def text_summary status = valid ? "VALID" : "INVALID" lines = [] lines << "Font: #{font_path}" lines << "Status: #{status}" lines << "" lines << "Summary:" lines << " Errors: #{summary.errors}" lines << " Warnings: #{summary.warnings}" lines << " Info: #{summary.info}" if issues.any? lines << "" lines << "Issues:" issues.each do |issue| severity_marker = case issue.severity when "error" then "[ERROR]" when "warning" then "[WARN]" when "info" then "[INFO]" end location_info = issue.location ? " (#{issue.location})" : "" lines << " #{severity_marker} #{issue.category}: #{issue.}#{location_info}" end end lines.join("\n") end |
#to_summary ⇒ String
Generate brief summary
410 411 412 |
# File 'lib/fontisan/models/validation_report.rb', line 410 def to_summary "#{summary.errors} errors, #{summary.warnings} warnings, #{summary.info} info" end |
#to_table_format ⇒ String
Generate tabular format for CLI
417 418 419 420 421 422 423 424 425 426 427 |
# File 'lib/fontisan/models/validation_report.rb', line 417 def to_table_format lines = [] lines << "CHECK_ID | STATUS | SEVERITY | TABLE" lines << "-" * 60 check_results.each do |cr| status = cr.passed ? "PASS" : "FAIL" table = cr.table || "N/A" lines << "#{cr.check_id} | #{status} | #{cr.severity} | #{table}" end lines.join("\n") end |
#to_text_report ⇒ String
Generate full detailed text report
403 404 405 |
# File 'lib/fontisan/models/validation_report.rb', line 403 def to_text_report text_summary end |
#valid? ⇒ Boolean
Check if font is valid (alias for valid attribute)
255 256 257 |
# File 'lib/fontisan/models/validation_report.rb', line 255 def valid? valid end |
#warnings ⇒ Array<Issue>
Get all warning issues
189 190 191 |
# File 'lib/fontisan/models/validation_report.rb', line 189 def warnings issues.select { |issue| issue.severity == "warning" } end |
#warnings_only ⇒ Array<Issue>
Get warning issues only
308 309 310 |
# File 'lib/fontisan/models/validation_report.rb', line 308 def warnings_only issues_by_severity(:warning) end |