Class: Cabriolet::ValidationReport

Inherits:
Object
  • Object
show all
Defined in:
lib/cabriolet/validator.rb

Overview

Validation report object

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#errorsObject (readonly)

Returns the value of attribute errors.



255
256
257
# File 'lib/cabriolet/validator.rb', line 255

def errors
  @errors
end

#formatObject (readonly)

Returns the value of attribute format.



255
256
257
# File 'lib/cabriolet/validator.rb', line 255

def format
  @format
end

#levelObject (readonly)

Returns the value of attribute level.



255
256
257
# File 'lib/cabriolet/validator.rb', line 255

def level
  @level
end

#pathObject (readonly)

Returns the value of attribute path.



255
256
257
# File 'lib/cabriolet/validator.rb', line 255

def path
  @path
end

#validObject (readonly)

Returns the value of attribute valid.



255
256
257
# File 'lib/cabriolet/validator.rb', line 255

def valid
  @valid
end

#warningsObject (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_reportObject



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

Returns:

  • (Boolean)


270
271
272
# File 'lib/cabriolet/validator.rb', line 270

def has_errors?
  !@errors.empty?
end

#has_warnings?Boolean

Returns:

  • (Boolean)


274
275
276
# File 'lib/cabriolet/validator.rb', line 274

def has_warnings?
  !@warnings.empty?
end

#summaryObject



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_hObject



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

Returns:

  • (Boolean)


266
267
268
# File 'lib/cabriolet/validator.rb', line 266

def valid?
  @valid
end