Module: Chemicalml::Convention::Base
- Included in:
- Compchem, Dictionary, Molecular, UnitDictionary, UnitTypeDictionary
- Defined in:
- lib/chemicalml/convention/base.rb
Overview
Mixin that gives a convention module its registry behavior:
- `qname` / `namespace_uri` (must be implemented by the host)
- `constraints` (lazy array)
- `register(SomeConstraintClass)`
- `validate(document)` -> [Violation, ...]
The framework never inspects which constraints a convention has;
it just walks whatever was registered. Adding a new rule = a new
constraint subclass + a register call.
Instance Method Summary collapse
- #constraint_count ⇒ Object
- #constraints ⇒ Object
- #namespace_uri ⇒ Object
- #qname ⇒ Object
- #register(constraint_class) ⇒ Object
- #reset_constraints! ⇒ Object
- #validate(document) ⇒ Object
Instance Method Details
#constraint_count ⇒ Object
39 40 41 |
# File 'lib/chemicalml/convention/base.rb', line 39 def constraint_count constraints.length end |
#constraints ⇒ Object
24 25 26 |
# File 'lib/chemicalml/convention/base.rb', line 24 def constraints @constraints ||= [] end |
#namespace_uri ⇒ Object
20 21 22 |
# File 'lib/chemicalml/convention/base.rb', line 20 def namespace_uri raise NotImplementedError, "#{name} must define its namespace URI" end |
#qname ⇒ Object
16 17 18 |
# File 'lib/chemicalml/convention/base.rb', line 16 def qname raise NotImplementedError, "#{name} must define its QName" end |
#register(constraint_class) ⇒ Object
28 29 30 31 |
# File 'lib/chemicalml/convention/base.rb', line 28 def register(constraint_class) constraints << constraint_class unless constraints.include?(constraint_class) self end |
#reset_constraints! ⇒ Object
43 44 45 |
# File 'lib/chemicalml/convention/base.rb', line 43 def reset_constraints! @constraints = [] end |
#validate(document) ⇒ Object
33 34 35 36 37 |
# File 'lib/chemicalml/convention/base.rb', line 33 def validate(document) constraints.flat_map do |klass| klass.new.check(document) end end |