Class: Chemicalml::Convention::UnitTypeDictionary::Constraints::UnitTypeMustHaveIdAndName

Inherits:
Constraint::NodeConstraint show all
Defined in:
lib/chemicalml/convention/unit_type_dictionary/constraints/unit_type_must_have_id_and_name.rb

Overview

Every unitType MUST have an id and a name attribute per the unitType-dictionary convention.

Instance Method Summary collapse

Methods inherited from Constraint::NodeConstraint

#check

Instance Method Details

#check_node(node, path) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/chemicalml/convention/unit_type_dictionary/constraints/unit_type_must_have_id_and_name.rb', line 10

def check_node(node, path)
  return [] unless unit_type?(node)

  violations = []
  if node.id.to_s.empty?
    violations << violation(path: path.join("/"),
                            message: "unitType must have an id")
  end
  if node.name.to_s.empty?
    violations << violation(path: path.join("/"),
                            message: "unitType must have a name")
  end
  violations
end