Class: Chemicalml::Convention::ValidationReport

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#violationsObject (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

#errorsObject



19
20
21
# File 'lib/chemicalml/convention/validation_report.rb', line 19

def errors
  @errors ||= violations.select(&:error?).freeze
end

#has_warnings?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/chemicalml/convention/validation_report.rb', line 31

def has_warnings?
  warnings.any?
end

#hashObject



54
55
56
# File 'lib/chemicalml/convention/validation_report.rb', line 54

def hash
  violations.hash
end

#ok?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/chemicalml/convention/validation_report.rb', line 27

def ok?
  errors.empty?
end

#sizeObject



35
36
37
# File 'lib/chemicalml/convention/validation_report.rb', line 35

def size
  violations.length
end

#to_sObject



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

#warningsObject



23
24
25
# File 'lib/chemicalml/convention/validation_report.rb', line 23

def warnings
  @warnings ||= violations.select(&:warning?).freeze
end