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
-
#summary ⇒ String
Human-readable multi-line summary.
- #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 |
# File 'lib/chemicalml/convention/validation_report.rb', line 39 def +(other) return other if other.nil? raise ArgumentError, "cannot combine ValidationReport with #{other.class}" unless other.is_a?(ValidationReport) ValidationReport.new(violations + other.violations) end |
#==(other) ⇒ Object Also known as: eql?
47 48 49 |
# File 'lib/chemicalml/convention/validation_report.rb', line 47 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
52 53 54 |
# File 'lib/chemicalml/convention/validation_report.rb', line 52 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 |
#summary ⇒ String
Human-readable multi-line summary. Suitable for CLI output and logging. Each violation is rendered with severity, path, and message (and value when present).
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/chemicalml/convention/validation_report.rb', line 65 def summary return 'OK — no violations' if ok? && !has_warnings? lines = [] lines << "Errors: #{errors.size}, Warnings: #{warnings.size}" unless errors.empty? lines << '' lines << 'Errors:' errors.each { |v| lines << " ERROR #{v.path}: #{v.}#{value_suffix(v)}" } end unless warnings.empty? lines << '' lines << 'Warnings:' warnings.each { |v| lines << " WARN #{v.path}: #{v.}#{value_suffix(v)}" } end lines.join("\n") end |
#to_s ⇒ Object
56 57 58 |
# File 'lib/chemicalml/convention/validation_report.rb', line 56 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 |