Class: Chemicalml::Convention::Compchem::Constraints::ScalarUnits

Inherits:
Chemicalml::Convention::Constraint::NodeConstraint show all
Includes:
ModulePredicates
Defined in:
lib/chemicalml/convention/compchem/constraints/scalar_units.rb

Overview

CompChem value-container rules: scalar with dataType xsd:integer or xsd:double MUST have units; scalar with dataType xsd:string MUST NOT have units.

Constant Summary collapse

NUMERIC_TYPES =
%w[xsd:integer xsd:double].freeze

Instance Method Summary collapse

Methods included from ModulePredicates

#calculation_module?, #child_modules_with, #cml_module?, #compchem_root?, #environment_module?, #finalization_module?, #initialization_module?, #job_list_module?, #job_module?

Methods inherited from Chemicalml::Convention::Constraint::NodeConstraint

#check

Instance Method Details

#check_node(node, path) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/chemicalml/convention/compchem/constraints/scalar_units.rb', line 16

def check_node(node, path)

  data_type = node.data_type.to_s
  units = node.units.to_s
  violations = []

  if NUMERIC_TYPES.include?(data_type) && units.empty?
    violations << violation(path: path.join('/'),
                            message: "scalar with dataType #{data_type.inspect} must have units")
  end
  if data_type == 'xsd:string' && !units.empty?
    violations << violation(path: path.join('/'),
                            message: "scalar with dataType 'xsd:string' must not have units")
  end
  violations
end