Class: Chemicalml::Convention::Violation

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

Instance Method Summary collapse

Constructor Details

#initialize(path:, message:, severity: :error, constraint: nil) ⇒ Violation

Returns a new instance of Violation.

Raises:

  • (ArgumentError)


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    = message
  @severity   = severity.to_sym
  @constraint = constraint
  freeze
end

Instance Attribute Details

#constraintObject (readonly)

Returns the value of attribute constraint.



11
12
13
# File 'lib/chemicalml/convention/violation.rb', line 11

def constraint
  @constraint
end

#messageObject (readonly)

Returns the value of attribute message.



11
12
13
# File 'lib/chemicalml/convention/violation.rb', line 11

def message
  @message
end

#pathObject (readonly)

Returns the value of attribute path.



11
12
13
# File 'lib/chemicalml/convention/violation.rb', line 11

def path
  @path
end

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

Returns:

  • (Boolean)


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

def error?
  severity == :error
end

#to_sObject



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

def to_s
  "#{severity.upcase} #{path}: #{message}"
end

#warning?Boolean

Returns:

  • (Boolean)


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

def warning?
  severity == :warning
end