Class: Cabriolet::ValidationReport
- Inherits:
-
Object
- Object
- Cabriolet::ValidationReport
- Defined in:
- lib/cabriolet/validator.rb
Overview
Validation report object
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#format ⇒ Object
readonly
Returns the value of attribute format.
-
#level ⇒ Object
readonly
Returns the value of attribute level.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#valid ⇒ Object
readonly
Returns the value of attribute valid.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
- #detailed_report ⇒ Object
- #has_errors? ⇒ Boolean
- #has_warnings? ⇒ Boolean
-
#initialize(valid:, format:, level:, errors:, warnings:, path:) ⇒ ValidationReport
constructor
A new instance of ValidationReport.
- #summary ⇒ Object
- #to_h ⇒ Object
- #to_json(*args) ⇒ Object
- #valid? ⇒ Boolean
Constructor Details
#initialize(valid:, format:, level:, errors:, warnings:, path:) ⇒ ValidationReport
Returns a new instance of ValidationReport.
257 258 259 260 261 262 263 264 |
# File 'lib/cabriolet/validator.rb', line 257 def initialize(valid:, format:, level:, errors:, warnings:, path:) @valid = valid @format = format @level = level @errors = errors @warnings = warnings @path = path end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
255 256 257 |
# File 'lib/cabriolet/validator.rb', line 255 def errors @errors end |
#format ⇒ Object (readonly)
Returns the value of attribute format.
255 256 257 |
# File 'lib/cabriolet/validator.rb', line 255 def format @format end |
#level ⇒ Object (readonly)
Returns the value of attribute level.
255 256 257 |
# File 'lib/cabriolet/validator.rb', line 255 def level @level end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
255 256 257 |
# File 'lib/cabriolet/validator.rb', line 255 def path @path end |
#valid ⇒ Object (readonly)
Returns the value of attribute valid.
255 256 257 |
# File 'lib/cabriolet/validator.rb', line 255 def valid @valid end |
#warnings ⇒ Object (readonly)
Returns the value of attribute warnings.
255 256 257 |
# File 'lib/cabriolet/validator.rb', line 255 def warnings @warnings end |
Instance Method Details
#detailed_report ⇒ Object
284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/cabriolet/validator.rb', line 284 def detailed_report report = ["=" * 60] report << "Validation Report" report << ("=" * 60) report << "File: #{@path}" report << "Format: #{@format}" report << "Level: #{@level}" report << "Status: #{valid? ? 'VALID' : 'INVALID'}" report << "" if has_errors? report << "ERRORS:" @errors.each_with_index do |error, i| report << " #{i + 1}. #{error}" end report << "" end if has_warnings? report << "WARNINGS:" @warnings.each_with_index do |warning, i| report << " #{i + 1}. #{warning}" end report << "" end report << ("=" * 60) report.join("\n") end |
#has_errors? ⇒ Boolean
270 271 272 |
# File 'lib/cabriolet/validator.rb', line 270 def has_errors? !@errors.empty? end |
#has_warnings? ⇒ Boolean
274 275 276 |
# File 'lib/cabriolet/validator.rb', line 274 def has_warnings? !@warnings.empty? end |
#summary ⇒ Object
278 279 280 281 282 |
# File 'lib/cabriolet/validator.rb', line 278 def summary status = valid? ? "VALID" : "INVALID" "#{status} - #{@format} archive (#{@level} validation)\n" \ "Errors: #{@errors.count}, Warnings: #{@warnings.count}" end |
#to_h ⇒ Object
314 315 316 317 318 319 320 321 322 323 324 325 |
# File 'lib/cabriolet/validator.rb', line 314 def to_h { valid: @valid, format: @format, level: @level, path: @path, error_count: @errors.count, warning_count: @warnings.count, errors: @errors, warnings: @warnings, } end |
#to_json(*args) ⇒ Object
327 328 329 330 |
# File 'lib/cabriolet/validator.rb', line 327 def to_json(*args) require "json" to_h.to_json(*args) end |
#valid? ⇒ Boolean
266 267 268 |
# File 'lib/cabriolet/validator.rb', line 266 def valid? @valid end |