Class: Chemicalml::Convention::Dictionary::Constraints::EntryUnitsCoConstraints
- Inherits:
-
Constraint::NodeConstraint
- Object
- Constraint
- Constraint::NodeConstraint
- Chemicalml::Convention::Dictionary::Constraints::EntryUnitsCoConstraints
- Defined in:
- lib/chemicalml/convention/dictionary/constraints/entry_units_co_constraints.rb
Overview
Co-constraint between unitType and units:
- If
unitTypeisunknown,unitsMUST NOT be present. - If
unitTypeisnone,unitsMUST be present and point tohttp://www.xml-cml.org/unit/si#none.
Constant Summary collapse
- NONE_UNITS =
'http://www.xml-cml.org/unit/si#none'
Instance Method Summary collapse
Methods inherited from Constraint::NodeConstraint
Instance Method Details
#check_node(node, path) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/chemicalml/convention/dictionary/constraints/entry_units_co_constraints.rb', line 16 def check_node(node, path) unit_type = node.unit_type.to_s units = node.units.to_s violations = [] if unit_type == 'unknown' && !units.empty? violations << violation(path: path.join('/'), message: "entry #{node.id.inspect} has unitType 'unknown' " \ 'and therefore must not have units') end if unit_type == 'none' && units != NONE_UNITS violations << violation(path: path.join('/'), message: "entry #{node.id.inspect} has unitType 'none' — " \ "units must be #{NONE_UNITS.inspect}") end violations end |