Class: Uniword::Validation::DocumentValidationReport
- Inherits:
-
Object
- Object
- Uniword::Validation::DocumentValidationReport
- Defined in:
- lib/uniword/validation/document_validator.rb
Overview
Validation report for document validation.
Aggregates results from all validation layers.
Instance Attribute Summary collapse
-
#file_path ⇒ String
readonly
Path to validated file.
-
#layer_results ⇒ Hash<String, LayerValidationResult>
readonly
Results by layer.
Instance Method Summary collapse
-
#add_layer_result(layer_name, result) ⇒ void
Add a layer validation result.
-
#critical_failures? ⇒ Boolean
Check if any layer has critical failures.
-
#errors ⇒ Array<Hash>
Get all errors from all layers.
-
#infos ⇒ Array<Hash>
Get all info messages from all layers.
-
#initialize(file_path) ⇒ DocumentValidationReport
constructor
Initialize a new report.
-
#summary ⇒ Hash
Get summary statistics.
-
#to_json(*_args) ⇒ String
Export to JSON string.
-
#to_s ⇒ String
Convert to string for display.
-
#valid? ⇒ Boolean
Check if document is valid overall.
-
#warnings ⇒ Array<Hash>
Get all warnings from all layers.
Constructor Details
#initialize(file_path) ⇒ DocumentValidationReport
Initialize a new report.
159 160 161 162 |
# File 'lib/uniword/validation/document_validator.rb', line 159 def initialize(file_path) @file_path = file_path @layer_results = {} end |
Instance Attribute Details
#file_path ⇒ String (readonly)
Returns Path to validated file.
151 152 153 |
# File 'lib/uniword/validation/document_validator.rb', line 151 def file_path @file_path end |
#layer_results ⇒ Hash<String, LayerValidationResult> (readonly)
Returns Results by layer.
154 155 156 |
# File 'lib/uniword/validation/document_validator.rb', line 154 def layer_results @layer_results end |
Instance Method Details
#add_layer_result(layer_name, result) ⇒ void
This method returns an undefined value.
Add a layer validation result.
169 170 171 |
# File 'lib/uniword/validation/document_validator.rb', line 169 def add_layer_result(layer_name, result) @layer_results[layer_name] = result end |
#critical_failures? ⇒ Boolean
Check if any layer has critical failures.
210 211 212 |
# File 'lib/uniword/validation/document_validator.rb', line 210 def critical_failures? @layer_results.values.any?(&:critical_failures?) end |
#errors ⇒ Array<Hash>
Get all errors from all layers.
183 184 185 186 187 |
# File 'lib/uniword/validation/document_validator.rb', line 183 def errors @layer_results.flat_map do |layer, result| result.errors.map { |err| err.merge(layer: layer) } end end |
#infos ⇒ Array<Hash>
Get all info messages from all layers.
201 202 203 204 205 |
# File 'lib/uniword/validation/document_validator.rb', line 201 def infos @layer_results.flat_map do |layer, result| result.infos.map { |info| info.merge(layer: layer) } end end |
#summary ⇒ Hash
Get summary statistics.
217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/uniword/validation/document_validator.rb', line 217 def summary { file: @file_path, valid: valid?, layers_validated: @layer_results.count, errors: errors.count, warnings: warnings.count, infos: infos.count, critical: critical_failures?, } end |
#to_json(*_args) ⇒ String
Export to JSON string.
232 233 234 235 236 237 |
# File 'lib/uniword/validation/document_validator.rb', line 232 def to_json(*_args) JSON.pretty_generate( summary: summary, layers: @layer_results.transform_values(&:to_h), ) end |
#to_s ⇒ String
Convert to string for display.
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/uniword/validation/document_validator.rb', line 242 def to_s lines = [ "Document Validation Report: #{@file_path}", "=" * 60, "", ] @layer_results.each_value do |result| lines << result.to_s end lines << "" lines << "Summary:" lines << " Valid: #{valid?}" lines << " Errors: #{errors.count}" lines << " Warnings: #{warnings.count}" lines << " Info: #{infos.count}" if errors.any? lines << "" lines << "Errors:" errors.each do |error| lines << " [#{error[:layer]}] #{error[:message]}" end end lines.join("\n") end |
#valid? ⇒ Boolean
Check if document is valid overall.
176 177 178 |
# File 'lib/uniword/validation/document_validator.rb', line 176 def valid? @layer_results.values.all?(&:valid?) end |
#warnings ⇒ Array<Hash>
Get all warnings from all layers.
192 193 194 195 196 |
# File 'lib/uniword/validation/document_validator.rb', line 192 def warnings @layer_results.flat_map do |layer, result| result.warnings.map { |warn| warn.merge(layer: layer) } end end |