Class: Fontisan::Models::ValidationReport

Inherits:
Lutaml::Model::Serializable
  • Object
show all
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.

Examples:

Creating a validation report

report = ValidationReport.new(
  font_path: "font.ttf",
  valid: false
)
report.add_error("tables", "Missing required table: glyf", nil)
report.add_warning("checksum", "Table 'name' checksum mismatch", "name table")

Serializing to YAML

yaml_output = report.to_yaml

Serializing to JSON

json_output = report.to_json

Defined Under Namespace

Classes: CheckResult, Issue, Summary

Instance Method Summary collapse

Instance Method Details

#add_error(category, message, location = nil) ⇒ void

This method returns an undefined value.

Add an error to the report

Parameters:

  • category (String)

    The error category (e.g., “tables”, “structure”)

  • message (String)

    The error message

  • location (String, nil) (defaults to: nil)

    The specific location of the error



136
137
138
139
140
141
142
143
144
145
# File 'lib/fontisan/models/validation_report.rb', line 136

def add_error(category, message, location = nil)
  issues << Issue.new(
    severity: "error",
    category: category,
    message: 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

Parameters:

  • category (String)

    The info category

  • message (String)

    The info message

  • location (String, nil) (defaults to: nil)

    The specific location



169
170
171
172
173
174
175
176
177
# File 'lib/fontisan/models/validation_report.rb', line 169

def add_info(category, message, location = nil)
  issues << Issue.new(
    severity: "info",
    category: category,
    message: 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

Parameters:

  • category (String)

    The warning category

  • message (String)

    The warning message

  • location (String, nil) (defaults to: nil)

    The specific location of the warning



153
154
155
156
157
158
159
160
161
# File 'lib/fontisan/models/validation_report.rb', line 153

def add_warning(category, message, location = nil)
  issues << Issue.new(
    severity: "warning",
    category: category,
    message: message,
    location: location,
  )
  summary.warnings += 1
end

#checks_by_status(passed:) ⇒ Array<CheckResult>

Get checks by status

Parameters:

  • passed (Boolean)

    true for passed checks, false for failed checks

Returns:

  • (Array<CheckResult>)

    Array of checks with the specified 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

#errorsArray<Issue>

Get all error issues

Returns:

  • (Array<Issue>)

    Array of error issues



182
183
184
# File 'lib/fontisan/models/validation_report.rb', line 182

def errors
  issues.select { |issue| issue.severity == "error" }
end

#errors_onlyArray<Issue>

Get error issues only

Returns:

  • (Array<Issue>)

    Array of error issues



301
302
303
# File 'lib/fontisan/models/validation_report.rb', line 301

def errors_only
  issues_by_severity(:error)
end

#failed_check_idsArray<String>

Get IDs of failed checks

Returns:

  • (Array<String>)

    Array of failed check IDs



359
360
361
# File 'lib/fontisan/models/validation_report.rb', line 359

def failed_check_ids
  failed_checks.map(&:check_id)
end

#failed_checksArray<CheckResult>

Get all failed checks

Returns:



277
278
279
# File 'lib/fontisan/models/validation_report.rb', line 277

def failed_checks
  check_results.reject(&:passed)
end

#failure_rateFloat

Calculate failure rate as percentage

Returns:

  • (Float)

    Failure rate (0.0 to 1.0)



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_errorsArray<Issue>

Get fatal error issues

Returns:

  • (Array<Issue>)

    Array of 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

Parameters:

  • table_tag (String)

    Table tag

  • field_name (String, Symbol)

    Field name

Returns:

  • (Array<CheckResult>)

    Array of check results for the field



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

Returns:

  • (Boolean)

    true if errors exist



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

Returns:

  • (Boolean)

    true if warnings exist



210
211
212
# File 'lib/fontisan/models/validation_report.rb', line 210

def has_warnings?
  summary.warnings.positive?
end

#info_issuesArray<Issue>

Get all info issues

Returns:

  • (Array<Issue>)

    Array of 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_onlyArray<Issue>

Get info issues only

Returns:

  • (Array<Issue>)

    Array of info issues



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

Parameters:

  • category (String)

    Category name

Returns:

  • (Array<Issue>)

    Array of issues in the specified 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

Parameters:

  • severity (Symbol, String)

    Severity level

Returns:

  • (Array<Issue>)

    Array of issues with the specified severity



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_rateFloat

Calculate pass rate as percentage

Returns:

  • (Float)

    Pass rate (0.0 to 1.0)



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)

Returns:

  • (Boolean)

    true if font passed validation



248
249
250
# File 'lib/fontisan/models/validation_report.rb', line 248

def passed?
  valid
end

#passed_check_idsArray<String>

Get IDs of passed checks

Returns:

  • (Array<String>)

    Array of passed check IDs



366
367
368
# File 'lib/fontisan/models/validation_report.rb', line 366

def passed_check_ids
  passed_checks.map(&:check_id)
end

#passed_checksArray<CheckResult>

Get all passed checks

Returns:



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

Parameters:

  • check_id (Symbol, String)

    The check identifier

Returns:

  • (CheckResult, nil)

    The check result or nil if not found



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_distributionHash

Get severity distribution

Returns:

  • (Hash)

    Hash with :errors, :warnings, :info counts



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

Parameters:

  • table_tag (String)

    Table tag (e.g., ‘name’, ‘head’)

Returns:

  • (Array<CheckResult>)

    Array of check results for the 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_summaryString

Get a text summary of the validation

Returns:

  • (String)

    Human-readable summary



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.message}#{location_info}"
    end
  end

  lines.join("\n")
end

#to_summaryString

Generate brief summary

Returns:

  • (String)

    Brief summary string



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_formatString

Generate tabular format for CLI

Returns:

  • (String)

    Tabular format output



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_reportString

Generate full detailed text report

Returns:

  • (String)

    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)

Returns:

  • (Boolean)

    true if font is valid



255
256
257
# File 'lib/fontisan/models/validation_report.rb', line 255

def valid?
  valid
end

#warningsArray<Issue>

Get all warning issues

Returns:

  • (Array<Issue>)

    Array of warning issues



189
190
191
# File 'lib/fontisan/models/validation_report.rb', line 189

def warnings
  issues.select { |issue| issue.severity == "warning" }
end

#warnings_onlyArray<Issue>

Get warning issues only

Returns:

  • (Array<Issue>)

    Array of warning issues



308
309
310
# File 'lib/fontisan/models/validation_report.rb', line 308

def warnings_only
  issues_by_severity(:warning)
end