Class: YES::Constraints::Inclusive
- Inherits:
-
TreeConstraint
- Object
- AbstractConstraint
- TreeConstraint
- YES::Constraints::Inclusive
- Defined in:
- lib/yes/constraints/inclusive.rb
Overview
Inclusion can either be a boolean expression in which case it validates that there is at least one matching node. Otherwise, the value is taken to be a ypath and validates that there are matching paths if the main selection is present. – TODO: Provide $parent$ path substitution ? ++
Instance Attribute Summary
Attributes inherited from AbstractConstraint
Class Method Summary collapse
-
.applicable?(spec) ⇒ Boolean
Only applicable if ‘inclusive` field in in the spec.
- .checklist(spec, tree, nodes) ⇒ Array<Constraint>
Instance Method Summary collapse
-
#valid? ⇒ Boolean
Validate inclusion - This can either be a boolean expression in which case it validates that there is at least one matching node.
Methods inherited from AbstractConstraint
#applicable?, inherited, #initialize, #match_delta, #recurse_valid?, #validate
Constructor Details
This class inherits a constructor from YES::Constraints::AbstractConstraint
Class Method Details
.applicable?(spec) ⇒ Boolean
Only applicable if ‘inclusive` field in in the spec.
22 23 24 |
# File 'lib/yes/constraints/inclusive.rb', line 22 def self.applicable?(spec) spec['inclusive'] end |
.checklist(spec, tree, nodes) ⇒ Array<Constraint>
16 17 18 19 |
# File 'lib/yes/constraints/inclusive.rb', line 16 def self.checklist(spec, tree, nodes) return [] unless applicable?(spec) [new(spec, tree, nodes)] end |
Instance Method Details
#valid? ⇒ Boolean
Validate inclusion - This can either be a boolean expression in which case it validates that there is at least one matching node. Otherwise, the value is taken to be a ypath and validates that there are matching paths if the main selection is present.
32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/yes/constraints/inclusive.rb', line 32 def valid? return true unless applicable? inclusive = spec['inclusive'] case inclusive when true, false nodes.size > 0 else in_nodes = tree.select(inclusive) nodes.size == 0 or in_nodes.size > 0 end end |