Class: YES::Constraints::Choice
- Inherits:
-
NodeConstraint
- Object
- AbstractConstraint
- NodeConstraint
- YES::Constraints::Choice
- Defined in:
- lib/yes/constraints/choice.rb
Overview
Validate from a selction of choices.
choice: [M,F]
Instance Attribute Summary
Attributes inherited from NodeConstraint
Attributes inherited from AbstractConstraint
Class Method Summary collapse
-
.applicable?(spec) ⇒ Boolean
Only applicable if ‘choice` field is in spec.
- .checklist(spec, tree, nodes) ⇒ Array<Constraint>
Instance Method Summary collapse
-
#validate(spec) ⇒ Boolean
Validate that a node’s value is amoung a provided list of values.
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
Only applicable if ‘choice` field is in spec.
21 22 23 |
# File 'lib/yes/constraints/choice.rb', line 21 def self.applicable?(spec) spec['choice'] end |
.checklist(spec, tree, nodes) ⇒ Array<Constraint>
13 14 15 16 17 18 |
# File 'lib/yes/constraints/choice.rb', line 13 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 that a node’s value is amoung a provided list of values.
29 30 31 32 |
# File 'lib/yes/constraints/choice.rb', line 29 def validate(spec) choice = Array(spec['choice']) choice.include?(node.transform) end |