Class: Lutaml::Xsd::ValidationResult
- Inherits:
-
Model::Serializable
- Object
- Model::Serializable
- Lutaml::Xsd::ValidationResult
- Defined in:
- lib/lutaml/xsd/validation_result.rb
Overview
Result of validation with error collection
Class Method Summary collapse
-
.failure(errors) ⇒ ValidationResult
Create failure result with errors.
-
.success ⇒ ValidationResult
Create success result.
Instance Method Summary collapse
-
#error_count ⇒ Integer
Get error count.
-
#error_messages ⇒ Array<String>
Get all error messages.
-
#errors_for(field) ⇒ Array<ValidationError>
Get errors for specific field.
-
#invalid? ⇒ Boolean
Check if validation failed.
-
#to_s ⇒ String
Format as human-readable string.
-
#valid? ⇒ Boolean
Check if validation passed.
-
#validate! ⇒ Object
Raise error if validation failed.
Class Method Details
.failure(errors) ⇒ ValidationResult
Create failure result with errors
27 28 29 |
# File 'lib/lutaml/xsd/validation_result.rb', line 27 def self.failure(errors) new(valid: false, errors: errors) end |
.success ⇒ ValidationResult
Create success result
20 21 22 |
# File 'lib/lutaml/xsd/validation_result.rb', line 20 def self.success new(valid: true, errors: []) end |
Instance Method Details
#error_count ⇒ Integer
Get error count
45 46 47 |
# File 'lib/lutaml/xsd/validation_result.rb', line 45 def error_count (errors || []).size end |
#error_messages ⇒ Array<String>
Get all error messages
51 52 53 |
# File 'lib/lutaml/xsd/validation_result.rb', line 51 def (errors || []).map(&:message) end |
#errors_for(field) ⇒ Array<ValidationError>
Get errors for specific field
58 59 60 61 |
# File 'lib/lutaml/xsd/validation_result.rb', line 58 def errors_for(field) field_str = field.to_s (errors || []).select { |e| e.field == field_str } end |
#invalid? ⇒ Boolean
Check if validation failed
39 40 41 |
# File 'lib/lutaml/xsd/validation_result.rb', line 39 def invalid? !valid end |
#to_s ⇒ String
Format as human-readable string
65 66 67 68 69 70 71 72 73 |
# File 'lib/lutaml/xsd/validation_result.rb', line 65 def to_s return "Valid" if valid? lines = ["Validation failed with #{error_count} error(s):"] errors.each_with_index do |error, idx| lines << " #{idx + 1}. #{error}" end lines.join("\n") end |
#valid? ⇒ Boolean
Check if validation passed
33 34 35 |
# File 'lib/lutaml/xsd/validation_result.rb', line 33 def valid? valid end |
#validate! ⇒ Object
Raise error if validation failed
77 78 79 |
# File 'lib/lutaml/xsd/validation_result.rb', line 77 def validate! raise ValidationFailedError.new(self) if invalid? end |