Class: YES::Constraints::Length
- Inherits:
-
NodeConstraint
- Object
- AbstractConstraint
- NodeConstraint
- YES::Constraints::Length
- Defined in:
- lib/yes/constraints/length.rb
Overview
Validate if a node’s value is within a certain length. The value is converted to a string using #to_s for the comparison.
//code:
length: 3
A valid code value could then have no more than three characters.
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 value is within a certain length.
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
27 28 29 |
# File 'lib/yes/constraints/length.rb', line 27 def self.applicable?(spec) spec['length'] end |
.checklist(spec, tree, nodes) ⇒ Array<Constraint>
18 19 20 21 22 23 |
# File 'lib/yes/constraints/length.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 value is within a certain length. The value is converted to a string using #to_s for the comparison.
37 38 39 40 |
# File 'lib/yes/constraints/length.rb', line 37 def validate(spec) length = spec['length'] match_delta(length, node.value.to_s.size) end |