Class: OpenEHR::Parser::ArchetypeValidator
- Inherits:
-
Object
- Object
- OpenEHR::Parser::ArchetypeValidator
- Defined in:
- lib/openehr/parser/archetype_validator.rb
Overview
Post-parse semantic validator, checking a parsed archetype against the VARID..VDFPT rules (Beale07, p.100). VARID/VARDF/ VARON/VDFAI are already enforced structurally by the RM/AM object model itself (their setters raise on construction), so they can never actually fail here - they're still checked explicitly, both for rule-traceability and so a validator run against a duck-typed object (not necessarily a real OpenEHR::AM::Archetype::Archetype) stays honest.
Constant Summary collapse
- Validation =
Exception::Validation
Instance Method Summary collapse
- #errors ⇒ Object
-
#initialize(archetype) ⇒ ArchetypeValidator
constructor
A new instance of ArchetypeValidator.
- #valid? ⇒ Boolean
- #validate! ⇒ Object
-
#validate_instance(rm_root) ⇒ Object
Checks
rm_rootagainst the archetype's definition, returning a path-annotated OpenEHR::Parser::Exception::Validation:: InstanceNonConformant for the first violation found (path resolved via rm_root.path_of_item, the PATHABLE navigation method), or [] when rm_root fully conforms.
Constructor Details
#initialize(archetype) ⇒ ArchetypeValidator
Returns a new instance of ArchetypeValidator.
16 17 18 |
# File 'lib/openehr/parser/archetype_validator.rb', line 16 def initialize(archetype) @archetype = archetype end |
Instance Method Details
#errors ⇒ Object
20 21 22 |
# File 'lib/openehr/parser/archetype_validator.rb', line 20 def errors RULES.filter_map { |rule| send(rule) } end |
#valid? ⇒ Boolean
24 25 26 |
# File 'lib/openehr/parser/archetype_validator.rb', line 24 def valid? errors.empty? end |
#validate! ⇒ Object
28 29 30 31 |
# File 'lib/openehr/parser/archetype_validator.rb', line 28 def validate! error = errors.first raise error if error end |
#validate_instance(rm_root) ⇒ Object
Checks rm_root against the archetype's definition, returning
a path-annotated OpenEHR::Parser::Exception::Validation::
InstanceNonConformant for the first violation found (path
resolved via rm_root.path_of_item, the PATHABLE navigation
method), or [] when rm_root fully conforms.
38 39 40 41 42 43 44 |
# File 'lib/openehr/parser/archetype_validator.rb', line 38 def validate_instance(rm_root) return [] if @archetype.definition.valid_value?(rm_root) _node, value = @archetype.definition.find_violation(rm_root) = "value does not conform to #{@archetype.archetype_id.value}" [Validation::InstanceNonConformant.new(, resolve_path(rm_root, value))] end |