Class: Lutaml::Xsd::Validation::ValidationResult
- Inherits:
-
Object
- Object
- Lutaml::Xsd::Validation::ValidationResult
- Defined in:
- lib/lutaml/xsd/validation/validation_result.rb
Overview
ValidationResult holds the outcome of XML validation
This class encapsulates the complete result of validating an XML document against XSD schemas. It tracks whether validation succeeded, collects all errors and warnings, and provides methods for querying and formatting the results.
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#infos ⇒ Object
readonly
Returns the value of attribute infos.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#all_issues ⇒ Array<ValidationError>
Get all issues (errors and warnings combined).
-
#detailed_report(include_warnings: true) ⇒ String
Generate detailed report.
-
#error_count ⇒ Integer
Get total number of errors.
-
#errors? ⇒ Boolean
Check if there are any errors.
-
#errors_at(location) ⇒ Array<ValidationError>
Get errors for a specific location.
-
#errors_by_code ⇒ Hash<String, Array<ValidationError>>
Get errors grouped by code.
-
#errors_by_severity(severity) ⇒ Array<ValidationError>
Get errors by severity level.
-
#first_error ⇒ ValidationError?
Get first error.
-
#first_warning ⇒ ValidationError?
Get first warning.
-
#has_error_code?(code) ⇒ Boolean
Check if result has specific error code.
-
#initialize(valid:, errors: [], warnings: [], infos: []) ⇒ ValidationResult
constructor
Initialize a new ValidationResult.
-
#invalid? ⇒ Boolean
Check if validation failed.
-
#summary ⇒ String
Generate a human-readable summary.
-
#to_h ⇒ Hash
Convert result to hash representation.
-
#to_json ⇒ String
Convert result to JSON.
-
#total_issues ⇒ Integer
Get total number of issues (errors + warnings).
-
#valid? ⇒ Boolean
Check if validation succeeded.
-
#warning_count ⇒ Integer
Get total number of warnings.
-
#warnings? ⇒ Boolean
Check if there are any warnings.
Constructor Details
#initialize(valid:, errors: [], warnings: [], infos: []) ⇒ ValidationResult
Initialize a new ValidationResult
35 36 37 38 39 40 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 35 def initialize(valid:, errors: [], warnings: [], infos: []) @valid = valid @errors = errors @warnings = warnings @infos = infos end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
27 28 29 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 27 def errors @errors end |
#infos ⇒ Object (readonly)
Returns the value of attribute infos.
27 28 29 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 27 def infos @infos end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
27 28 29 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 27 def warnings @warnings end |
Instance Method Details
#all_issues ⇒ Array<ValidationError>
Get all issues (errors and warnings combined)
102 103 104 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 102 def all_issues @errors + @warnings end |
#detailed_report(include_warnings: true) ⇒ String
Generate detailed report
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 158 def detailed_report(include_warnings: true) lines = [] lines << summary lines << "" if @errors.any? lines << "Errors:" @errors.each_with_index do |error, index| lines << " #{index + 1}. #{error.}" end lines << "" end if include_warnings && @warnings.any? lines << "Warnings:" @warnings.each_with_index do |warning, index| lines << " #{index + 1}. #{warning.}" end lines << "" end lines.join("\n") end |
#error_count ⇒ Integer
Get total number of errors
59 60 61 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 59 def error_count @errors.size end |
#errors? ⇒ Boolean
Check if there are any errors
80 81 82 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 80 def errors? @errors.any? end |
#errors_at(location) ⇒ Array<ValidationError>
Get errors for a specific location
117 118 119 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 117 def errors_at(location) @errors.select { |e| e.location == location } end |
#errors_by_code ⇒ Hash<String, Array<ValidationError>>
Get errors grouped by code
109 110 111 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 109 def errors_by_code @errors.group_by(&:code) end |
#errors_by_severity(severity) ⇒ Array<ValidationError>
Get errors by severity level
95 96 97 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 95 def errors_by_severity(severity) all_issues.select { |issue| issue.severity == severity } end |
#first_error ⇒ ValidationError?
Get first error
193 194 195 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 193 def first_error @errors.first end |
#first_warning ⇒ ValidationError?
Get first warning
200 201 202 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 200 def first_warning @warnings.first end |
#has_error_code?(code) ⇒ Boolean
Check if result has specific error code
186 187 188 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 186 def has_error_code?(code) @errors.any? { |e| e.code == code } end |
#invalid? ⇒ Boolean
Check if validation failed
52 53 54 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 52 def invalid? !valid? end |
#summary ⇒ String
Generate a human-readable summary
124 125 126 127 128 129 130 131 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 124 def summary if valid? "✓ Validation successful (#{warning_count} warnings)" else "✗ Validation failed: #{error_count} errors, " \ "#{warning_count} warnings" end end |
#to_h ⇒ Hash
Convert result to hash representation
136 137 138 139 140 141 142 143 144 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 136 def to_h { valid: valid?, error_count: error_count, warning_count: warning_count, errors: @errors.map(&:to_h), warnings: @warnings.map(&:to_h), } end |
#to_json ⇒ String
Convert result to JSON
149 150 151 152 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 149 def to_json(*) require "json" to_h.to_json(*) end |
#total_issues ⇒ Integer
Get total number of issues (errors + warnings)
73 74 75 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 73 def total_issues error_count + warning_count end |
#valid? ⇒ Boolean
Check if validation succeeded
45 46 47 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 45 def valid? @valid && @errors.empty? end |
#warning_count ⇒ Integer
Get total number of warnings
66 67 68 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 66 def warning_count @warnings.size end |
#warnings? ⇒ Boolean
Check if there are any warnings
87 88 89 |
# File 'lib/lutaml/xsd/validation/validation_result.rb', line 87 def warnings? @warnings.any? end |