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: 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



93
94
95
96
97
98
99
100
101
102
# File 'lib/fontisan/models/validation_report.rb', line 93

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



126
127
128
129
130
131
132
133
134
# File 'lib/fontisan/models/validation_report.rb', line 126

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



110
111
112
113
114
115
116
117
118
# File 'lib/fontisan/models/validation_report.rb', line 110

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

#errorsArray<Issue>

Get all error issues

Returns:

  • (Array<Issue>)

    Array of error issues



139
140
141
# File 'lib/fontisan/models/validation_report.rb', line 139

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

#has_errors?Boolean

Check if report has errors

Returns:

  • (Boolean)

    true if errors exist



160
161
162
# File 'lib/fontisan/models/validation_report.rb', line 160

def has_errors?
  summary.errors.positive?
end

#has_warnings?Boolean

Check if report has warnings

Returns:

  • (Boolean)

    true if warnings exist



167
168
169
# File 'lib/fontisan/models/validation_report.rb', line 167

def has_warnings?
  summary.warnings.positive?
end

#info_issuesArray<Issue>

Get all info issues

Returns:

  • (Array<Issue>)

    Array of info issues



153
154
155
# File 'lib/fontisan/models/validation_report.rb', line 153

def info_issues
  issues.select { |issue| issue.severity == "info" }
end

#text_summaryString

Get a text summary of the validation

Returns:

  • (String)

    Human-readable summary



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
# File 'lib/fontisan/models/validation_report.rb', line 174

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

#warningsArray<Issue>

Get all warning issues

Returns:

  • (Array<Issue>)

    Array of warning issues



146
147
148
# File 'lib/fontisan/models/validation_report.rb', line 146

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