Class: Uniword::Validation::ValidationReport
- Inherits:
-
Object
- Object
- Uniword::Validation::ValidationReport
- Defined in:
- lib/uniword/validation/validation_report.rb
Overview
Aggregates and reports on validation results.
Responsibility: Collect, organize, and export validation results. Single Responsibility: Only manages validation reporting.
A validation report includes:
-
Collection of all validation results
-
Grouping by status and type
-
Summary statistics
-
Export capabilities (JSON, YAML, HTML)
Instance Attribute Summary collapse
-
#results ⇒ Array<ValidationResult>
readonly
All validation results.
Instance Method Summary collapse
-
#add_result(result) ⇒ ValidationReport
Add a validation result to the report.
-
#export_html(file_path) ⇒ void
Export report to HTML file.
-
#export_json(file_path) ⇒ void
Export report to JSON file.
-
#export_yaml(file_path) ⇒ void
Export report to YAML file.
-
#failure_count ⇒ Integer
Get count of failed validations.
-
#failures ⇒ Array<ValidationResult>
Get all failed results.
-
#group_by_type ⇒ Hash{Symbol => Array<ValidationResult>}
Group results by link type.
-
#initialize ⇒ ValidationReport
constructor
Initialize a new ValidationReport.
-
#success_count ⇒ Integer
Get count of successful validations.
-
#successes ⇒ Array<ValidationResult>
Get all successful results.
-
#summary ⇒ Hash
Get summary statistics.
-
#to_h ⇒ Hash
Convert to hash representation.
-
#to_html ⇒ String
Convert to HTML string.
-
#to_json ⇒ String
Convert to JSON string.
-
#to_s ⇒ String
Convert to string for display.
-
#to_yaml ⇒ String
Convert to YAML string.
-
#total_count ⇒ Integer
Get total count of results.
-
#unknown_count ⇒ Integer
Get count of unknown/skipped validations.
-
#unknowns ⇒ Array<ValidationResult>
Get all unknown/skipped results.
-
#valid? ⇒ Boolean
Check if all validations passed.
-
#warning_count ⇒ Integer
Get count of warnings.
-
#warnings ⇒ Array<ValidationResult>
Get all warning results.
Constructor Details
#initialize ⇒ ValidationReport
Initialize a new ValidationReport.
35 36 37 |
# File 'lib/uniword/validation/validation_report.rb', line 35 def initialize @results = [] end |
Instance Attribute Details
#results ⇒ Array<ValidationResult> (readonly)
Returns All validation results.
29 30 31 |
# File 'lib/uniword/validation/validation_report.rb', line 29 def results @results end |
Instance Method Details
#add_result(result) ⇒ ValidationReport
Add a validation result to the report.
46 47 48 49 50 51 52 |
# File 'lib/uniword/validation/validation_report.rb', line 46 def add_result(result) raise ArgumentError, "Expected ValidationResult" unless result.is_a?(ValidationResult) @results << result self end |
#export_html(file_path) ⇒ void
This method returns an undefined value.
Export report to HTML file.
214 215 216 |
# File 'lib/uniword/validation/validation_report.rb', line 214 def export_html(file_path) File.write(file_path, to_html) end |
#export_json(file_path) ⇒ void
This method returns an undefined value.
Export report to JSON file.
192 193 194 |
# File 'lib/uniword/validation/validation_report.rb', line 192 def export_json(file_path) File.write(file_path, to_json) end |
#export_yaml(file_path) ⇒ void
This method returns an undefined value.
Export report to YAML file.
203 204 205 |
# File 'lib/uniword/validation/validation_report.rb', line 203 def export_yaml(file_path) File.write(file_path, to_yaml) end |
#failure_count ⇒ Integer
Get count of failed validations.
120 121 122 |
# File 'lib/uniword/validation/validation_report.rb', line 120 def failure_count failures.count end |
#failures ⇒ Array<ValidationResult>
Get all failed results.
80 81 82 |
# File 'lib/uniword/validation/validation_report.rb', line 80 def failures @results.select(&:failure?) end |
#group_by_type ⇒ Hash{Symbol => Array<ValidationResult>}
Group results by link type.
161 162 163 164 165 |
# File 'lib/uniword/validation/validation_report.rb', line 161 def group_by_type @results.group_by do |result| classify_link_type(result.link) end end |
#success_count ⇒ Integer
Get count of successful validations.
110 111 112 |
# File 'lib/uniword/validation/validation_report.rb', line 110 def success_count successes.count end |
#successes ⇒ Array<ValidationResult>
Get all successful results.
70 71 72 |
# File 'lib/uniword/validation/validation_report.rb', line 70 def successes @results.select(&:valid?) end |
#summary ⇒ Hash
Get summary statistics.
174 175 176 177 178 179 180 181 182 183 |
# File 'lib/uniword/validation/validation_report.rb', line 174 def summary { total: total_count, successes: success_count, failures: failure_count, warnings: warning_count, unknowns: unknown_count, valid: valid? } end |
#to_h ⇒ Hash
Convert to hash representation.
279 280 281 282 283 284 285 286 287 |
# File 'lib/uniword/validation/validation_report.rb', line 279 def to_h { summary: summary, results: @results.map(&:to_h), by_type: group_by_type.transform_values do |results| results.map(&:to_h) end } end |
#to_html ⇒ String
Convert to HTML string.
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 270 271 |
# File 'lib/uniword/validation/validation_report.rb', line 244 def to_html <<~HTML <!DOCTYPE html> <html> <head> <title>Link Validation Report</title> <style> body { font-family: Arial, sans-serif; margin: 20px; } h1 { color: #333; } .summary { background: #f5f5f5; padding: 15px; border-radius: 5px; margin-bottom: 20px; } .summary-item { display: inline-block; margin-right: 20px; } table { border-collapse: collapse; width: 100%; margin-top: 20px; } th, td { border: 1px solid #ddd; padding: 8px; text-align: left; } th { background-color: #4CAF50; color: white; } .success { color: green; } .failure { color: red; } .warning { color: orange; } .unknown { color: gray; } </style> </head> <body> <h1>Link Validation Report</h1> #{summary_html} #{results_table_html} </body> </html> HTML end |
#to_json ⇒ String
Convert to JSON string.
224 225 226 |
# File 'lib/uniword/validation/validation_report.rb', line 224 def to_json(*) JSON.pretty_generate(to_h, *) end |
#to_s ⇒ String
Convert to string for display.
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# File 'lib/uniword/validation/validation_report.rb', line 295 def to_s lines = [ "Link Validation Report", "=" * 50, "Total: #{total_count}", "Successes: #{success_count}", "Failures: #{failure_count}", "Warnings: #{warning_count}", "Unknowns: #{unknown_count}", "Valid: #{valid?}", "" ] if failures.any? lines << "Failed Links:" failures.each do |result| lines << " - #{result}" end end if warnings.any? lines << "" lines << "Warnings:" warnings.each do |result| lines << " - #{result}" end end lines.join("\n") end |
#to_yaml ⇒ String
Convert to YAML string.
234 235 236 |
# File 'lib/uniword/validation/validation_report.rb', line 234 def to_yaml YAML.dump(to_h) end |
#total_count ⇒ Integer
Get total count of results.
150 151 152 |
# File 'lib/uniword/validation/validation_report.rb', line 150 def total_count @results.count end |
#unknown_count ⇒ Integer
Get count of unknown/skipped validations.
140 141 142 |
# File 'lib/uniword/validation/validation_report.rb', line 140 def unknown_count unknowns.count end |
#unknowns ⇒ Array<ValidationResult>
Get all unknown/skipped results.
100 101 102 |
# File 'lib/uniword/validation/validation_report.rb', line 100 def unknowns @results.select(&:unknown?) end |
#valid? ⇒ Boolean
Check if all validations passed.
60 61 62 |
# File 'lib/uniword/validation/validation_report.rb', line 60 def valid? @results.all?(&:valid?) end |
#warning_count ⇒ Integer
Get count of warnings.
130 131 132 |
# File 'lib/uniword/validation/validation_report.rb', line 130 def warning_count warnings.count end |
#warnings ⇒ Array<ValidationResult>
Get all warning results.
90 91 92 |
# File 'lib/uniword/validation/validation_report.rb', line 90 def warnings @results.select(&:warning?) end |