Class: Sirens::VirtualTreeModel::TreeNode

Inherits:
Object
  • Object
show all
Defined in:
lib/models/virtual_tree_model.rb

Overview

Tree node class

Instance Method Summary collapse

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

#childrenObject



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_childrenObject



145
146
147
# File 'lib/models/virtual_tree_model.rb', line 145

def get_children()
    @get_children_block.call(value)
end

#valueObject



127
128
129
# File 'lib/models/virtual_tree_model.rb', line 127

def value()
    @value
end