Class: Chemicalml::Convention::Molecular::Constraints::AtomIdMustMatchPattern

Inherits:
Constraint::NodeConstraint show all
Defined in:
lib/chemicalml/convention/molecular/constraints/atom_id_must_match_pattern.rb

Constant Summary collapse

ID_PATTERN =
/\A[A-Za-z][A-Za-z0-9._\-]*\z/.freeze

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
# File 'lib/chemicalml/convention/molecular/constraints/atom_id_must_match_pattern.rb', line 10

def check_node(node, path)
  return [] unless node.is_a?(Chemicalml::Cml::Role::Atom)

  id = node.id.to_s
  return [] if id.empty?
  return [] if id.match?(ID_PATTERN)

  [violation(path: path.empty? ? "atom" : path.join("/"),
             message: "atom id #{id.inspect} must start with a letter and " \
                      "contain only letters, digits, dot, hyphen, or underscore",
             severity: :warning)]
end