Class: YES::Constraints::Range
- Inherits:
-
NodeConstraint
- Object
- AbstractConstraint
- NodeConstraint
- YES::Constraints::Range
- Defined in:
- lib/yes/constraints/range.rb
Overview
Validate the a nodes value is within a certain range. Primarily this works for numeric values, but it can also work for string in ASCII/UTF-8 order, by using a 2-element array for comparison.
//note:
range: ['A','G']
Valid values for are then only A, B, C, D, E, F and G.
Instance Attribute Summary
Attributes inherited from NodeConstraint
Attributes inherited from AbstractConstraint
Class Method Summary collapse
Instance Method Summary collapse
-
#validate(spec) ⇒ Boolean
Validate if a node is the only one of it’s value in a sequence or mapping.
Methods inherited from NodeConstraint
Methods inherited from AbstractConstraint
#applicable?, inherited, #initialize, #match_delta, #recurse_valid?, #valid?
Constructor Details
This class inherits a constructor from YES::Constraints::NodeConstraint
Class Method Details
.applicable?(spec) ⇒ Boolean
26 27 28 |
# File 'lib/yes/constraints/range.rb', line 26 def self.applicable?(spec) spec['range'] end |
.checklist(spec, tree, nodes) ⇒ Array<Validaiton>
18 19 20 21 22 23 |
# File 'lib/yes/constraints/range.rb', line 18 def self.checklist(spec, tree, nodes) return [] unless applicable?(spec) nodes.map do |node| new(spec, tree, node) end end |
Instance Method Details
#validate(spec) ⇒ Boolean
Validate if a node is the only one of it’s value in a sequence or mapping.
34 35 36 37 |
# File 'lib/yes/constraints/range.rb', line 34 def validate(spec) range = spec['range'] match_delta(range, node.transform) ? true : false end |