Class: YES::Constraints::Count
- Inherits:
-
TreeConstraint
- Object
- AbstractConstraint
- TreeConstraint
- YES::Constraints::Count
- Defined in:
- lib/yes/constraints/count.rb
Overview
Count validation ensures there are a limited number of matching nodes in a document.
//gold:
count: 1..4
Would mean the ‘gold` mapping key could only appear 1 to 4 times in the entire document.
Instance Attribute Summary
Attributes inherited from AbstractConstraint
Class Method Summary collapse
-
.applicable?(spec) ⇒ Boolean
Only applicable if ‘count` entry is in the spec.
- .checklist(spec, tree, nodes) ⇒ Array<Constraint>
Instance Method Summary collapse
-
#validate(spec) ⇒ Object
Validate count ensure there is a minimum and/or maximum number of matching nodes.
Methods inherited from AbstractConstraint
#applicable?, inherited, #initialize, #match_delta, #recurse_valid?, #valid?
Constructor Details
This class inherits a constructor from YES::Constraints::AbstractConstraint
Class Method Details
.applicable?(spec) ⇒ Boolean
Only applicable if ‘count` entry is in the spec.
23 24 25 |
# File 'lib/yes/constraints/count.rb', line 23 def self.applicable?(spec) spec['count'] end |
.checklist(spec, tree, nodes) ⇒ Array<Constraint>
17 18 19 20 |
# File 'lib/yes/constraints/count.rb', line 17 def self.checklist(spec, tree, nodes) return [] unless applicable?(spec) [new(spec, tree, nodes)] end |
Instance Method Details
#validate(spec) ⇒ Object
Validate count ensure there is a minimum and/or maximum number of matching nodes.
29 30 31 32 |
# File 'lib/yes/constraints/count.rb', line 29 def validate(spec) count = spec['count'] match_delta(count, nodes.size) end |