Module: Ecoportal::API::GraphQL::Helpers::LocationsTree

Included in:
Base::LocationStructure
Defined in:
lib/ecoportal/api/graphql/helpers/locations_tree.rb

Instance Method Summary collapse

Instance Method Details

#treeify(nodes) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/ecoportal/api/graphql/helpers/locations_tree.rb', line 6

def treeify(nodes)
  parents = nodes.each_with_object({}) do |node, parents|
    parent   = node.parent
    # puts "Node '#{node.name}' with ID: '#{node.id}'. "
    # puts "  • Parent '#{parent.name}' with ID: '#{parent.id}'." if parent
    parentId = parent && parent.id.upcase
    (parents[parentId] ||= []).push(node)
  end
  get_children(nil, parents)
end