Class: Chemicalml::Convention::Violation
- Inherits:
-
Object
- Object
- Chemicalml::Convention::Violation
- Defined in:
- lib/chemicalml/convention/violation.rb
Overview
Value object describing one constraint violation. Severity is
either :error (document is invalid under the convention) or
:warning (document is valid but problematic).
value carries the offending value where natural (e.g. the
duplicated atom id, the malformed unit symbol). Optional —
constraints that flag a missing attribute leave value nil.
Constant Summary collapse
- SEVERITIES =
%i[error warning].freeze
Instance Attribute Summary collapse
-
#constraint ⇒ Object
readonly
Returns the value of attribute constraint.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#severity ⇒ Object
readonly
Returns the value of attribute severity.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize(path:, message:, severity: :error, constraint: nil, value: nil) ⇒ Violation
constructor
A new instance of Violation.
- #to_s ⇒ Object
- #warning? ⇒ Boolean
Constructor Details
#initialize(path:, message:, severity: :error, constraint: nil, value: nil) ⇒ Violation
Returns a new instance of Violation.
17 18 19 20 21 22 23 24 25 26 |
# File 'lib/chemicalml/convention/violation.rb', line 17 def initialize(path:, message:, severity: :error, constraint: nil, value: nil) raise ArgumentError, "unknown severity: #{severity.inspect}" unless SEVERITIES.include?(severity.to_sym) @path = path @message = @severity = severity.to_sym @constraint = constraint @value = value freeze end |
Instance Attribute Details
#constraint ⇒ Object (readonly)
Returns the value of attribute constraint.
15 16 17 |
# File 'lib/chemicalml/convention/violation.rb', line 15 def constraint @constraint end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
15 16 17 |
# File 'lib/chemicalml/convention/violation.rb', line 15 def @message end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
15 16 17 |
# File 'lib/chemicalml/convention/violation.rb', line 15 def path @path end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
15 16 17 |
# File 'lib/chemicalml/convention/violation.rb', line 15 def severity @severity end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
15 16 17 |
# File 'lib/chemicalml/convention/violation.rb', line 15 def value @value end |
Instance Method Details
#error? ⇒ Boolean
28 29 30 |
# File 'lib/chemicalml/convention/violation.rb', line 28 def error? severity == :error end |
#to_s ⇒ Object
36 37 38 39 |
# File 'lib/chemicalml/convention/violation.rb', line 36 def to_s suffix = value.nil? ? '' : " (value=#{value.inspect})" "#{severity.upcase} #{path}: #{}#{suffix}" end |
#warning? ⇒ Boolean
32 33 34 |
# File 'lib/chemicalml/convention/violation.rb', line 32 def warning? severity == :warning end |