Module: Eco::Data::Locations::NodeBase::Treeify

Includes:
Language::AuxiliarLogger
Included in:
Builder, Parsing, Serial
Defined in:
lib/eco/data/locations/node_base/treeify.rb

Overview

Note:

expects nodes to have these properties:

  1. id, name and parentId
  2. parent
  3. tracked_level

Generic treeifier

Instance Attribute Summary

Attributes included from Language::AuxiliarLogger

#logger

Instance Method Summary collapse

Methods included from Language::AuxiliarLogger

#log

Instance Method Details

#treeify(nodes) {|NodeBase| ... } ⇒ Array<Hash>

Note:

if block is no given, it auto-detects the serializer block.

Returns a hierarchical tree of nested Hashes via nodes key.

Yields:

Yield Returns:

  • (Hash)

    custom hash model when treeifying (allows to set more keys/properties).

Returns:

  • (Array<Hash>)

    a hierarchical tree of nested Hashes via nodes key.



15
16
17
18
19
# File 'lib/eco/data/locations/node_base/treeify.rb', line 15

def treeify(nodes, &block)
  return [] if nodes.empty?
  block ||= nodes.first.class.serializer
  get_children(nil, parents_hash(nodes), &block)
end