Class: Chemicalml::Convention::Dictionary::Constraints::EntryIdMustMatchPattern

Inherits:
Constraint::NodeConstraint show all
Defined in:
lib/chemicalml/convention/dictionary/constraints/entry_id_must_match_pattern.rb

Overview

An <entry> id MUST match [A-Za-z][A-Za-z0-9._-]* — start with a letter, followed by letters/digits/dot/hyphen/ underscore. Mirrors the upstream IdStartChar / IdChar BNF.

Constant Summary collapse

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

Instance Method Summary collapse

Methods inherited from Constraint::NodeConstraint

#check

Instance Method Details

#check_node(node, path) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/chemicalml/convention/dictionary/constraints/entry_id_must_match_pattern.rb', line 14

def check_node(node, path)

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

  [violation(path: path.join('/'),
             message: "entry id #{id.inspect} must match [A-Za-z][A-Za-z0-9._-]*")]
end