Class: Chemicalml::Convention::ValidationReport
- Inherits:
-
Object
- Object
- Chemicalml::Convention::ValidationReport
- Defined in:
- lib/chemicalml/convention/validation_report.rb
Overview
Value object wrapping the violations returned by validate.
Gives callers severity-based views without losing the raw array
(still exposed as #violations).
Constructed by Convention.validate_report (new API) —
Convention.validate keeps its array return shape so existing
callers don't break.
Instance Attribute Summary collapse
-
#violations ⇒ Object
readonly
Returns the value of attribute violations.
Instance Method Summary collapse
- #+(other) ⇒ Object
- #==(other) ⇒ Object (also: #eql?)
- #errors ⇒ Object
- #has_warnings? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(violations) ⇒ ValidationReport
constructor
A new instance of ValidationReport.
- #ok? ⇒ Boolean
- #size ⇒ Object
- #to_s ⇒ Object
- #warnings ⇒ Object
Constructor Details
#initialize(violations) ⇒ ValidationReport
Returns a new instance of ValidationReport.
15 16 17 |
# File 'lib/chemicalml/convention/validation_report.rb', line 15 def initialize(violations) @violations = violations.to_a.freeze end |
Instance Attribute Details
#violations ⇒ Object (readonly)
Returns the value of attribute violations.
13 14 15 |
# File 'lib/chemicalml/convention/validation_report.rb', line 13 def violations @violations end |
Instance Method Details
#+(other) ⇒ Object
39 40 41 42 43 44 45 46 47 |
# File 'lib/chemicalml/convention/validation_report.rb', line 39 def +(other) return other if other.nil? unless other.is_a?(ValidationReport) raise ArgumentError, "cannot combine ValidationReport with #{other.class}" end ValidationReport.new(violations + other.violations) end |
#==(other) ⇒ Object Also known as: eql?
49 50 51 |
# File 'lib/chemicalml/convention/validation_report.rb', line 49 def ==(other) other.is_a?(ValidationReport) && violations == other.violations end |
#errors ⇒ Object
19 20 21 |
# File 'lib/chemicalml/convention/validation_report.rb', line 19 def errors @errors ||= violations.select(&:error?).freeze end |
#has_warnings? ⇒ Boolean
31 32 33 |
# File 'lib/chemicalml/convention/validation_report.rb', line 31 def has_warnings? warnings.any? end |
#hash ⇒ Object
54 55 56 |
# File 'lib/chemicalml/convention/validation_report.rb', line 54 def hash violations.hash end |
#ok? ⇒ Boolean
27 28 29 |
# File 'lib/chemicalml/convention/validation_report.rb', line 27 def ok? errors.empty? end |
#size ⇒ Object
35 36 37 |
# File 'lib/chemicalml/convention/validation_report.rb', line 35 def size violations.length end |
#to_s ⇒ Object
58 59 60 |
# File 'lib/chemicalml/convention/validation_report.rb', line 58 def to_s "#{size} violation(s): #{errors.length} error(s), #{warnings.length} warning(s)" end |
#warnings ⇒ Object
23 24 25 |
# File 'lib/chemicalml/convention/validation_report.rb', line 23 def warnings @warnings ||= violations.select(&:warning?).freeze end |