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(*args) ⇒ 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.
24 25 26 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 24 def initialize @messages = [] end |
Instance Attribute Details
#messages ⇒ Object (readonly)
Returns the value of attribute messages.
22 23 24 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 22 def @messages end |
Instance Method Details
#add_error(**args) ⇒ ValidationMessage
Adds an error message to the result
32 33 34 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 32 def add_error(**args) (severity: :error, **args) end |
#add_info(**args) ⇒ ValidationMessage
Adds an info message to the result
48 49 50 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 48 def add_info(**args) (severity: :info, **args) end |
#add_message(**args) ⇒ ValidationMessage
Adds a message to the result
56 57 58 59 60 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 56 def (**args) = ValidationMessage.new(**args) @messages << end |
#add_warning(**args) ⇒ ValidationMessage
Adds a warning message to the result
40 41 42 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 40 def add_warning(**args) (severity: :warning, **args) end |
#by_category(category) ⇒ Array<ValidationMessage>
Returns messages filtered by category
123 124 125 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 123 def by_category(category) @messages.select { |m| m.category == category } end |
#by_entity_type(entity_type) ⇒ Array<ValidationMessage>
Returns messages filtered by entity type
131 132 133 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 131 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
115 116 117 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 115 def by_severity(severity) @messages.select { |m| m.severity == severity } end |
#errors ⇒ Array<ValidationMessage>
Returns all error messages
93 94 95 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 93 def errors @messages.select(&:error?) end |
#grouped_by_category ⇒ Hash<Symbol, Array<ValidationMessage>>
Returns messages grouped by category
138 139 140 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 138 def grouped_by_category @messages.group_by(&:category) end |
#grouped_by_entity_type ⇒ Hash<Symbol, Array<ValidationMessage>>
Returns messages grouped by entity type
152 153 154 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 152 def grouped_by_entity_type @messages.group_by(&:entity_type) end |
#grouped_by_severity ⇒ Hash<Symbol, Array<ValidationMessage>>
Returns messages grouped by severity
145 146 147 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 145 def grouped_by_severity @messages.group_by(&:severity) end |
#has_errors? ⇒ Boolean
Checks if there are any error messages
65 66 67 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 65 def has_errors? @messages.any?(&:error?) end |
#has_info? ⇒ Boolean
Checks if there are any info messages
79 80 81 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 79 def has_info? @messages.any?(&:info?) end |
#has_warnings? ⇒ Boolean
Checks if there are any warning messages
72 73 74 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 72 def has_warnings? @messages.any?(&:warning?) end |
#info ⇒ Array<ValidationMessage>
Returns all info messages
107 108 109 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 107 def info @messages.select(&:info?) end |
#merge!(other) ⇒ self
Merges another result into this one
187 188 189 190 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 187 def merge!(other) @messages.concat(other.) self end |
#statistics ⇒ Hash
Returns summary statistics
159 160 161 162 163 164 165 166 167 168 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 159 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
173 174 175 176 177 178 179 180 181 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 173 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
195 196 197 198 199 200 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 195 def to_h { statistics: statistics, messages: @messages.map(&:to_h), } end |
#to_json(*args) ⇒ String
Returns a JSON representation
205 206 207 208 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 205 def to_json(*args) require "json" to_h.to_json(*args) end |
#valid? ⇒ Boolean
Checks if the result is valid (no errors)
86 87 88 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 86 def valid? !has_errors? end |
#warnings ⇒ Array<ValidationMessage>
Returns all warning messages
100 101 102 |
# File 'lib/lutaml/qea/validation/validation_result.rb', line 100 def warnings @messages.select(&:warning?) end |