Class: Sirens::VirtualTreeModel::TreeNode
- Inherits:
-
Object
- Object
- Sirens::VirtualTreeModel::TreeNode
- Defined in:
- lib/models/virtual_tree_model.rb
Overview
Tree node class
Instance Method Summary collapse
- #child_at(index:) ⇒ Object
- #children ⇒ Object
- #get_children ⇒ Object
-
#initialize(value:, get_children_block:) ⇒ TreeNode
constructor
A new instance of TreeNode.
- #value ⇒ Object
Constructor Details
#initialize(value:, get_children_block:) ⇒ TreeNode
Returns a new instance of TreeNode.
121 122 123 124 125 |
# File 'lib/models/virtual_tree_model.rb', line 121 def initialize(value:, get_children_block:) @value = value @children = nil @get_children_block = get_children_block end |
Instance Method Details
#child_at(index:) ⇒ Object
141 142 143 |
# File 'lib/models/virtual_tree_model.rb', line 141 def child_at(index:) children[index] end |
#children ⇒ Object
131 132 133 134 135 136 137 138 139 |
# File 'lib/models/virtual_tree_model.rb', line 131 def children() if @children.nil? @children = get_children.collect{ |item| self.class.new(value: item, get_children_block: @get_children_block) } end @children end |
#get_children ⇒ Object
145 146 147 |
# File 'lib/models/virtual_tree_model.rb', line 145 def get_children() @get_children_block.call(value) end |
#value ⇒ Object
127 128 129 |
# File 'lib/models/virtual_tree_model.rb', line 127 def value() @value end |