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).
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.
Instance Method Summary collapse
- #error? ⇒ Boolean
-
#initialize(path:, message:, severity: :error, constraint: nil) ⇒ Violation
constructor
A new instance of Violation.
- #to_s ⇒ Object
- #warning? ⇒ Boolean
Constructor Details
#initialize(path:, message:, severity: :error, constraint: nil) ⇒ Violation
Returns a new instance of Violation.
13 14 15 16 17 18 19 20 21 |
# File 'lib/chemicalml/convention/violation.rb', line 13 def initialize(path:, message:, severity: :error, constraint: nil) raise ArgumentError, "unknown severity: #{severity.inspect}" unless SEVERITIES.include?(severity.to_sym) @path = path @message = @severity = severity.to_sym @constraint = constraint freeze end |
Instance Attribute Details
#constraint ⇒ Object (readonly)
Returns the value of attribute constraint.
11 12 13 |
# File 'lib/chemicalml/convention/violation.rb', line 11 def constraint @constraint end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
11 12 13 |
# File 'lib/chemicalml/convention/violation.rb', line 11 def @message end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
11 12 13 |
# File 'lib/chemicalml/convention/violation.rb', line 11 def path @path end |
#severity ⇒ Object (readonly)
Returns the value of attribute severity.
11 12 13 |
# File 'lib/chemicalml/convention/violation.rb', line 11 def severity @severity end |
Instance Method Details
#error? ⇒ Boolean
23 24 25 |
# File 'lib/chemicalml/convention/violation.rb', line 23 def error? severity == :error end |
#to_s ⇒ Object
31 32 33 |
# File 'lib/chemicalml/convention/violation.rb', line 31 def to_s "#{severity.upcase} #{path}: #{}" end |
#warning? ⇒ Boolean
27 28 29 |
# File 'lib/chemicalml/convention/violation.rb', line 27 def warning? severity == :warning end |