Class: Lutaml::Qea::Validation::ValidationResult
- Inherits:
-
Object
- Object
- Lutaml::Qea::Validation::ValidationResult
- Defined in:
- lib/lutaml/qea/validation/validation_result.rb
Overview
Collects and organizes validation messages, providing summary statistics and filtering capabilities
Instance Attribute Summary collapse
-
#messages ⇒ Object
readonly
Returns the value of attribute messages.
Instance Method Summary collapse
-
#add_error(**args) ⇒ ValidationMessage
Adds an error message to the result.
-
#add_info(**args) ⇒ ValidationMessage
Adds an info message to the result.
-
#add_message(**args) ⇒ ValidationMessage
Adds a message to the result.
-
#add_warning(**args) ⇒ ValidationMessage
Adds a warning message to the result.
-
#by_category(category) ⇒ Array<ValidationMessage>
Returns messages filtered by category.
-
#by_entity_type(entity_type) ⇒ Array<ValidationMessage>
Returns messages filtered by entity type.
-
#by_severity(severity) ⇒ Array<ValidationMessage>
Returns messages filtered by severity.
-
#errors ⇒ Array<ValidationMessage>
Returns all error messages.
-
#grouped_by_category ⇒ Hash<Symbol, Array<ValidationMessage>>
Returns messages grouped by category.
-
#grouped_by_entity_type ⇒ Hash<Symbol, Array<ValidationMessage>>
Returns messages grouped by entity type.
-
#grouped_by_severity ⇒ Hash<Symbol, Array<ValidationMessage>>
Returns messages grouped by severity.
-
#has_errors? ⇒ Boolean
Checks if there are any error messages.
-
#has_info? ⇒ Boolean
Checks if there are any info messages.
-
#has_warnings? ⇒ Boolean
Checks if there are any warning messages.
-
#info ⇒ Array<ValidationMessage>
Returns all info messages.
-
#initialize ⇒ ValidationResult
constructor
A new instance of ValidationResult.
-
#merge!(other) ⇒ self
Merges another result into this one.
-
#statistics ⇒ Hash
Returns summary statistics.
-
#summary ⇒ String
Returns a summary string.
-
#to_h ⇒ Hash
Returns a hash representation.
-
#to_json ⇒ String
Returns a JSON representation.
-
#valid? ⇒ Boolean
Checks if the result is valid (no errors).
-
#warnings ⇒ Array<ValidationMessage>
Returns all warning messages.
Constructor Details
#initialize ⇒ ValidationResult
Returns a new instance of ValidationResult.
22 23 24 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 22 def initialize @messages = [] end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
20 21 22 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 20 def @messages end |
Instance Method Details
#add_error(**args) ⇒ ValidationMessage
Adds an error message to the result
30 31 32 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 30 def add_error(**args) (severity: :error, **args) end |
#add_info(**args) ⇒ ValidationMessage
Adds an info message to the result
46 47 48 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 46 def add_info(**args) (severity: :info, **args) end |
#add_message(**args) ⇒ ValidationMessage
Adds a message to the result
54 55 56 57 58 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 54 def (**args) = ValidationMessage.new(**args) @messages << end |
#add_warning(**args) ⇒ ValidationMessage
Adds a warning message to the result
38 39 40 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 38 def add_warning(**args) (severity: :warning, **args) end |
#by_category(category) ⇒ Array<ValidationMessage>
Returns messages filtered by category
121 122 123 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 121 def by_category(category) @messages.select { |m| m.category == category } end |
#by_entity_type(entity_type) ⇒ Array<ValidationMessage>
Returns messages filtered by entity type
129 130 131 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 129 def by_entity_type(entity_type) @messages.select { |m| m.entity_type == entity_type } end |
#by_severity(severity) ⇒ Array<ValidationMessage>
Returns messages filtered by severity
113 114 115 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 113 def by_severity(severity) @messages.select { |m| m.severity == severity } end |
#errors ⇒ Array<ValidationMessage>
Returns all error messages
91 92 93 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 91 def errors @messages.select(&:error?) end |
#grouped_by_category ⇒ Hash<Symbol, Array<ValidationMessage>>
Returns messages grouped by category
136 137 138 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 136 def grouped_by_category @messages.group_by(&:category) end |
#grouped_by_entity_type ⇒ Hash<Symbol, Array<ValidationMessage>>
Returns messages grouped by entity type
150 151 152 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 150 def grouped_by_entity_type @messages.group_by(&:entity_type) end |
#grouped_by_severity ⇒ Hash<Symbol, Array<ValidationMessage>>
Returns messages grouped by severity
143 144 145 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 143 def grouped_by_severity @messages.group_by(&:severity) end |
#has_errors? ⇒ Boolean
Checks if there are any error messages
63 64 65 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 63 def has_errors? @messages.any?(&:error?) end |
#has_info? ⇒ Boolean
Checks if there are any info messages
77 78 79 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 77 def has_info? @messages.any?(&:info?) end |
#has_warnings? ⇒ Boolean
Checks if there are any warning messages
70 71 72 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 70 def has_warnings? @messages.any?(&:warning?) end |
#info ⇒ Array<ValidationMessage>
Returns all info messages
105 106 107 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 105 def info @messages.select(&:info?) end |
#merge!(other) ⇒ self
Merges another result into this one
185 186 187 188 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 185 def merge!(other) @messages.concat(other.) self end |
#statistics ⇒ Hash
Returns summary statistics
157 158 159 160 161 162 163 164 165 166 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 157 def statistics { total: @messages.size, errors: errors.size, warnings: warnings.size, info: info.size, by_category: grouped_by_category.transform_values(&:size), by_entity_type: grouped_by_entity_type.transform_values(&:size), } end |
#summary ⇒ String
Returns a summary string
171 172 173 174 175 176 177 178 179 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 171 def summary stats = statistics [ "Total Messages: #{stats[:total]}", "Errors: #{stats[:errors]}", "Warnings: #{stats[:warnings]}", "Info: #{stats[:info]}", ].join("\n") end |
#to_h ⇒ Hash
Returns a hash representation
193 194 195 196 197 198 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 193 def to_h { statistics: statistics, messages: @messages.map(&:to_h), } end |
#to_json ⇒ String
Returns a JSON representation
203 204 205 206 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 203 def to_json(*) require "json" to_h.to_json(*) end |
#valid? ⇒ Boolean
Checks if the result is valid (no errors)
84 85 86 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 84 def valid? !has_errors? end |
#warnings ⇒ Array<ValidationMessage>
Returns all warning messages
98 99 100 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 98 def warnings @messages.select(&:warning?) end |