Class: Forester::TreeFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/forester/tree_factory.rb

Instance Method Summary collapse

Instance Method Details

#from_root_hash(root_hash, options = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/forester/tree_factory.rb', line 3

def from_root_hash(root_hash, options = {})
  default_options = {
    max_depth: :none,
  }
  options = default_options.merge(options)

  options[:max_depth] = -2 if options[:max_depth] == :none

  dummy_root = TreeNode.new('<TEMP>')

  tree = with_children(dummy_root, [root_hash], options.fetch(:children_key), options[:max_depth] + 1).first_child
  tree.detached_subtree_copy
end

#node_from_content(content) ⇒ Object



17
18
19
# File 'lib/forester/tree_factory.rb', line 17

def node_from_content(content)
  TreeNode.new(SecureRandom.uuid, content)
end