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



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

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



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

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



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

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



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

#errorsArray<Issue>

Get all error issues

Returns:

  • (Array<Issue>)

    Array of error issues



184
185
186
# File 'lib/fontisan/models/validation_report.rb', line 184

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

#errors_onlyArray<Issue>

Get error issues only

Returns:

  • (Array<Issue>)

    Array of error issues



303
304
305
# File 'lib/fontisan/models/validation_report.rb', line 303

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



363
364
365
# File 'lib/fontisan/models/validation_report.rb', line 363

def failed_check_ids
  failed_checks.map(&:check_id)
end

#failed_checksArray<CheckResult>

Get all failed checks

Returns:



279
280
281
# File 'lib/fontisan/models/validation_report.rb', line 279

def failed_checks
  check_results.reject(&:passed)
end

#failure_rateFloat

Calculate failure rate as percentage

Returns:

  • (Float)

    Failure rate (0.0 to 1.0)



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

Get fatal error issues

Returns:

  • (Array<Issue>)

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

Parameters:

  • table_tag (String)

    Table tag

  • field_name (String, Symbol)

    Field name

Returns:

  • (Array<CheckResult>)

    Array of check results for the field



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

Returns:

  • (Boolean)

    true if errors exist



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

Returns:

  • (Boolean)

    true if warnings exist



212
213
214
# File 'lib/fontisan/models/validation_report.rb', line 212

def has_warnings?
  summary.warnings.positive?
end

#info_issuesArray<Issue>

Get all info issues

Returns:

  • (Array<Issue>)

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

Get info issues only

Returns:

  • (Array<Issue>)

    Array of info issues



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

Parameters:

  • category (String)

    Category name

Returns:

  • (Array<Issue>)

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

Parameters:

  • severity (Symbol, String)

    Severity level

Returns:

  • (Array<Issue>)

    Array of issues with the specified severity



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_rateFloat

Calculate pass rate as percentage

Returns:

  • (Float)

    Pass rate (0.0 to 1.0)



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)

Returns:

  • (Boolean)

    true if font passed validation



250
251
252
# File 'lib/fontisan/models/validation_report.rb', line 250

def passed?
  valid
end

#passed_check_idsArray<String>

Get IDs of passed checks

Returns:

  • (Array<String>)

    Array of passed check IDs



370
371
372
# File 'lib/fontisan/models/validation_report.rb', line 370

def passed_check_ids
  passed_checks.map(&:check_id)
end

#passed_checksArray<CheckResult>

Get all passed checks

Returns:



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

Parameters:

  • check_id (Symbol, String)

    The check identifier

Returns:

  • (CheckResult, nil)

    The check result or nil if not found



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_distributionHash

Get severity distribution

Returns:

  • (Hash)

    Hash with :errors, :warnings, :info counts



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

Parameters:

  • table_tag (String)

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

Returns:

  • (Array<CheckResult>)

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

Get a text summary of the validation

Returns:

  • (String)

    Human-readable summary



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

  lines.join("\n")
end

#to_summaryString

Generate brief summary

Returns:

  • (String)

    Brief summary string



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_formatString

Generate tabular format for CLI

Returns:

  • (String)

    Tabular format output



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_reportString

Generate full detailed text report

Returns:

  • (String)

    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)

Returns:

  • (Boolean)

    true if font is valid



257
258
259
# File 'lib/fontisan/models/validation_report.rb', line 257

def valid?
  valid
end

#warningsArray<Issue>

Get all warning issues

Returns:

  • (Array<Issue>)

    Array of warning issues



191
192
193
# File 'lib/fontisan/models/validation_report.rb', line 191

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

#warnings_onlyArray<Issue>

Get warning issues only

Returns:

  • (Array<Issue>)

    Array of warning issues



310
311
312
# File 'lib/fontisan/models/validation_report.rb', line 310

def warnings_only
  issues_by_severity(:warning)
end