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
138 139 140 141 142 143 144 145 146 147 |
# File 'lib/fontisan/models/validation_report.rb', line 138 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
171 172 173 174 175 176 177 178 179 |
# File 'lib/fontisan/models/validation_report.rb', line 171 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
155 156 157 158 159 160 161 162 163 |
# File 'lib/fontisan/models/validation_report.rb', line 155 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
356 357 358 |
# File 'lib/fontisan/models/validation_report.rb', line 356 def checks_by_status(passed:) check_results.select { |cr| cr.passed == passed } end |
#errors ⇒ Array<Issue>
Get all error issues
184 185 186 |
# File 'lib/fontisan/models/validation_report.rb', line 184 def errors issues.select { |issue| issue.severity == "error" } end |
#errors_only ⇒ Array<Issue>
Get error issues only
303 304 305 |
# File 'lib/fontisan/models/validation_report.rb', line 303 def errors_only issues_by_severity(:error) end |
#failed_check_ids ⇒ Array<String>
Get IDs of failed checks
363 364 365 |
# File 'lib/fontisan/models/validation_report.rb', line 363 def failed_check_ids failed_checks.map(&:check_id) end |
#failed_checks ⇒ Array<CheckResult>
Get all failed checks
279 280 281 |
# File 'lib/fontisan/models/validation_report.rb', line 279 def failed_checks check_results.reject(&:passed) end |
#failure_rate ⇒ Float
Calculate failure rate as percentage
379 380 381 382 383 |
# File 'lib/fontisan/models/validation_report.rb', line 379 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
296 297 298 |
# File 'lib/fontisan/models/validation_report.rb', line 296 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
344 345 346 347 348 |
# File 'lib/fontisan/models/validation_report.rb', line 344 def field_issues(table_tag, field_name) check_results.select do |cr| cr.table == table_tag.to_s && cr.field == field_name.to_s end end |
#has_errors? ⇒ Boolean
Check if report has errors
205 206 207 |
# File 'lib/fontisan/models/validation_report.rb', line 205 def has_errors? summary.errors.positive? end |
#has_warnings? ⇒ Boolean
Check if report has warnings
212 213 214 |
# File 'lib/fontisan/models/validation_report.rb', line 212 def has_warnings? summary.warnings.positive? end |
#info_issues ⇒ Array<Issue>
Get all info issues
198 199 200 |
# File 'lib/fontisan/models/validation_report.rb', line 198 def info_issues issues.select { |issue| issue.severity == "info" } end |
#info_only ⇒ Array<Issue>
Get info issues only
317 318 319 |
# File 'lib/fontisan/models/validation_report.rb', line 317 def info_only issues_by_severity(:info) end |
#issues_by_category(category) ⇒ Array<Issue>
Get issues by category
327 328 329 |
# File 'lib/fontisan/models/validation_report.rb', line 327 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
289 290 291 |
# File 'lib/fontisan/models/validation_report.rb', line 289 def issues_by_severity(severity) issues.select { |issue| issue.severity == severity.to_s } end |
#pass_rate ⇒ Float
Calculate pass rate as percentage
388 389 390 |
# File 'lib/fontisan/models/validation_report.rb', line 388 def pass_rate 1.0 - failure_rate end |
#passed? ⇒ Boolean
Check if font passed validation (alias for valid)
250 251 252 |
# File 'lib/fontisan/models/validation_report.rb', line 250 def passed? valid end |
#passed_check_ids ⇒ Array<String>
Get IDs of passed checks
370 371 372 |
# File 'lib/fontisan/models/validation_report.rb', line 370 def passed_check_ids passed_checks.map(&:check_id) end |
#passed_checks ⇒ Array<CheckResult>
Get all passed checks
272 273 274 |
# File 'lib/fontisan/models/validation_report.rb', line 272 def passed_checks check_results.select(&:passed) end |
#result_of(check_id) ⇒ CheckResult?
Get result for a specific check by ID
265 266 267 |
# File 'lib/fontisan/models/validation_report.rb', line 265 def result_of(check_id) check_results.find { |cr| cr.check_id == check_id.to_s } end |
#severity_distribution ⇒ Hash
Get severity distribution
395 396 397 398 399 400 401 |
# File 'lib/fontisan/models/validation_report.rb', line 395 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
335 336 337 |
# File 'lib/fontisan/models/validation_report.rb', line 335 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
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 244 245 |
# File 'lib/fontisan/models/validation_report.rb', line 219 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
415 416 417 |
# File 'lib/fontisan/models/validation_report.rb', line 415 def to_summary "#{summary.errors} errors, #{summary.warnings} warnings, #{summary.info} info" end |
#to_table_format ⇒ String
Generate tabular format for CLI
422 423 424 425 426 427 428 429 430 431 432 |
# File 'lib/fontisan/models/validation_report.rb', line 422 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
408 409 410 |
# File 'lib/fontisan/models/validation_report.rb', line 408 def to_text_report text_summary end |
#valid? ⇒ Boolean
Check if font is valid (alias for valid attribute)
257 258 259 |
# File 'lib/fontisan/models/validation_report.rb', line 257 def valid? valid end |
#warnings ⇒ Array<Issue>
Get all warning issues
191 192 193 |
# File 'lib/fontisan/models/validation_report.rb', line 191 def warnings issues.select { |issue| issue.severity == "warning" } end |
#warnings_only ⇒ Array<Issue>
Get warning issues only
310 311 312 |
# File 'lib/fontisan/models/validation_report.rb', line 310 def warnings_only issues_by_severity(:warning) end |