Class: YES::Constraints::Kind
- Inherits:
-
NodeConstraint
- Object
- AbstractConstraint
- NodeConstraint
- YES::Constraints::Kind
- Defined in:
- lib/yes/constraints/kind.rb
Overview
Validate the kind of node. There are only three kinds of nodes: ‘scalar`, `map` and `seq`.
Instance Attribute Summary
Attributes inherited from NodeConstraint
Attributes inherited from AbstractConstraint
Class Method Summary collapse
Instance Method Summary collapse
-
#validate(spec) ⇒ Object
Validate type.
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
20 21 22 |
# File 'lib/yes/constraints/kind.rb', line 20 def self.applicable?(spec) spec['kind'] end |
.checklist(spec, tree, nodes) ⇒ Array<Constraint>
12 13 14 15 16 17 |
# File 'lib/yes/constraints/kind.rb', line 12 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) ⇒ Object
Validate type.
26 27 28 |
# File 'lib/yes/constraints/kind.rb', line 26 def validate(spec) node.kind.to_s == spec['kind'] end |