Class: Chemicalml::Convention::UnitDictionary::Constraints::UnitMustHaveSymbolAndUnitType
- Inherits:
-
Constraint::NodeConstraint
- Object
- Constraint
- Constraint::NodeConstraint
- Chemicalml::Convention::UnitDictionary::Constraints::UnitMustHaveSymbolAndUnitType
- Defined in:
- lib/chemicalml/convention/unit_dictionary/constraints/unit_must_have_symbol_and_unit_type.rb
Overview
Every unit MUST have id, title, symbol, parentSI,
at least one of multiplierToSI/constantToSI, and
unitType per the unit-dictionary convention.
Constant Summary collapse
- REQUIRED =
%i[title symbol parent_si unit_type].freeze
Instance Method Summary collapse
Methods inherited from Constraint::NodeConstraint
Instance Method Details
#check_node(node, path) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/chemicalml/convention/unit_dictionary/constraints/unit_must_have_symbol_and_unit_type.rb', line 13 def check_node(node, path) return [] unless unit?(node) violations = [] REQUIRED.each do |attr| val = node.public_send(attr) next unless val.to_s.empty? violations << violation(path: path.join("/"), message: "unit must have #{attr} (id=#{node.id.inspect})") end unless has_si_conversion?(node) violations << violation(path: path.join("/"), message: "unit must have multiplierToSI or constantToSI (id=#{node.id.inspect})") end violations end |