Class: DecisionAgent::Dmn::TreeNode
- Inherits:
-
Object
- Object
- DecisionAgent::Dmn::TreeNode
- Defined in:
- lib/decision_agent/dmn/decision_tree.rb
Overview
Represents a node in a decision tree
Instance Attribute Summary collapse
-
#children ⇒ Object
readonly
Returns the value of attribute children.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#decision ⇒ Object
readonly
Returns the value of attribute decision.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #add_child(node) ⇒ Object
-
#initialize(id:, label: nil, condition: nil, decision: nil) ⇒ TreeNode
constructor
A new instance of TreeNode.
- #leaf? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(id:, label: nil, condition: nil, decision: nil) ⇒ TreeNode
Returns a new instance of TreeNode.
13 14 15 16 17 18 19 20 |
# File 'lib/decision_agent/dmn/decision_tree.rb', line 13 def initialize(id:, label: nil, condition: nil, decision: nil) @id = id @label = label @condition = condition # FEEL expression to evaluate @decision = decision # Output decision if this is a leaf node @children = [] @parent = nil end |
Instance Attribute Details
#children ⇒ Object (readonly)
Returns the value of attribute children.
10 11 12 |
# File 'lib/decision_agent/dmn/decision_tree.rb', line 10 def children @children end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
10 11 12 |
# File 'lib/decision_agent/dmn/decision_tree.rb', line 10 def condition @condition end |
#decision ⇒ Object (readonly)
Returns the value of attribute decision.
10 11 12 |
# File 'lib/decision_agent/dmn/decision_tree.rb', line 10 def decision @decision end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/decision_agent/dmn/decision_tree.rb', line 10 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
10 11 12 |
# File 'lib/decision_agent/dmn/decision_tree.rb', line 10 def label @label end |
#parent ⇒ Object
Returns the value of attribute parent.
11 12 13 |
# File 'lib/decision_agent/dmn/decision_tree.rb', line 11 def parent @parent end |
Instance Method Details
#add_child(node) ⇒ Object
22 23 24 25 |
# File 'lib/decision_agent/dmn/decision_tree.rb', line 22 def add_child(node) node.parent = self @children << node end |
#leaf? ⇒ Boolean
27 28 29 |
# File 'lib/decision_agent/dmn/decision_tree.rb', line 27 def leaf? @children.empty? end |
#to_h ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/decision_agent/dmn/decision_tree.rb', line 31 def to_h { id: @id, label: @label, condition: @condition, decision: @decision, children: @children.map(&:to_h) } end |