Class: Chemicalml::Convention::Constraint

Inherits:
Object
  • Object
show all
Defined in:
lib/chemicalml/convention/constraint.rb

Overview

Abstract base class for a single constraint. Subclasses implement check_node (one node at a time) or check_document (whole document at once). The base class provides traversal and collection plumbing.

To add a new constraint:

1. Subclass `Constraint::NodeConstraint` or
 `Constraint::DocumentConstraint`
2. Implement `check_node` / `check_document`
3. Register it on the convention: `register(MyConstraint)`

No framework code changes.

Defined Under Namespace

Classes: DocumentConstraint, NodeConstraint

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.name_for_displayObject



19
20
21
# File 'lib/chemicalml/convention/constraint.rb', line 19

def self.name_for_display
  to_s.split("::").last
end

Instance Method Details

#check(_document) ⇒ Object

Raises:

  • (NotImplementedError)


23
24
25
26
# File 'lib/chemicalml/convention/constraint.rb', line 23

def check(_document)
  raise NotImplementedError,
        "#{self.class.name_for_display} must implement #check(document)"
end