Class: Metaschema::MetapathEvaluator
- Inherits:
-
Object
- Object
- Metaschema::MetapathEvaluator
- Defined in:
- lib/metaschema/metapath_evaluator.rb
Overview
Evaluates Metapath (XPath subset) expressions against Ruby object instances.
Supported patterns (covering OSCAL constraint targets):
"." — current instance
"@flag-name" — flag value
"child-name" — child field value
"child-name/@attr" — child's flag value
"//descendant" — descendant values
"child[@attr='val']" — filtered children
"child[@attr='val']/@attr2" — filtered child's attribute
"child[func(...)]/@attr" — function-based filter
".[condition]/path" — conditional navigation
".[condition]" — filter current instance
"(.)[condition]/path" — parenthesized self with filter
Supported predicate functions:
has-oscal-namespace('uri') — checks prop/element ns attribute
starts-with(@attr, 'prefix') — string prefix check
Supported predicate operators:
@attr='value' — attribute equals
@attr=('v1','v2',...) — attribute in set
and / or — logical operators
Constant Summary collapse
- OSCAL_NS =
"http://csrc.nist.gov/ns/oscal"
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
-
#initialize(context) ⇒ MetapathEvaluator
constructor
A new instance of MetapathEvaluator.
-
#resolve(path) ⇒ Object
Resolve a Metapath expression to values from the context instance.
-
#resolve_collection(path) ⇒ Object
Resolve a path to a collection of items (for uniqueness/cardinality checks).
Constructor Details
#initialize(context) ⇒ MetapathEvaluator
Returns a new instance of MetapathEvaluator.
33 34 35 |
# File 'lib/metaschema/metapath_evaluator.rb', line 33 def initialize(context) @context = context end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
31 32 33 |
# File 'lib/metaschema/metapath_evaluator.rb', line 31 def context @context end |
Instance Method Details
#resolve(path) ⇒ Object
Resolve a Metapath expression to values from the context instance. Returns an array of values.
39 40 41 42 43 44 45 |
# File 'lib/metaschema/metapath_evaluator.rb', line 39 def resolve(path) return [extract_value(@context)] if path == "." path = normalize_path(path) steps = parse_steps(path) evaluate_steps(@context, steps) end |
#resolve_collection(path) ⇒ Object
Resolve a path to a collection of items (for uniqueness/cardinality checks).
48 49 50 51 52 |
# File 'lib/metaschema/metapath_evaluator.rb', line 48 def resolve_collection(path) path = normalize_path(path) steps = parse_steps(path) evaluate_steps_collection(@context, steps) end |