Class: YES::Constraints::NodeConstraint

Inherits:
AbstractConstraint show all
Defined in:
lib/yes/constraints/node_constraint.rb

Overview

The NodeConstraint class is an abstract class and used for create constraint subclasses that apply constraints on a sigle node.

Direct Known Subclasses

Choice, FNMatch, Key, Kind, Length, Range, Regexp, Requires, Tag, Type, Value

Instance Attribute Summary collapse

Attributes inherited from AbstractConstraint

#nodes, #spec, #tree

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AbstractConstraint

#applicable?, checklist, inherited, #match_delta, #recurse_valid?, #valid?, #validate

Constructor Details

#initialize(spec, tree, node) ⇒ NodeConstraint

Like Abstract#initialize but takes a ‘node` qas well.



12
13
14
15
# File 'lib/yes/constraints/node_constraint.rb', line 12

def initialize(spec, tree, node)
  super(spec, tree, [node])
  @node = node
end

Instance Attribute Details

#nodeObject (readonly)

YAML Node.



20
21
22
# File 'lib/yes/constraints/node_constraint.rb', line 20

def node
  @node
end

Class Method Details

.applicable?(spec) ⇒ Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/yes/constraints/node_constraint.rb', line 47

def self.applicable?(spec)
  false
end

Instance Method Details

#tagObject

Get the applicable node’s tag.



23
24
25
# File 'lib/yes/constraints/node_constraint.rb', line 23

def tag
  node.type_id
end

#valueObject

Get the applicable node’s value.



28
29
30
# File 'lib/yes/constraints/node_constraint.rb', line 28

def value
  node.value
end