class Umwelt::Tree::Fill

Public Class Methods

new() click to toggle source
# File lib/umwelt/tree/fill.rb, line 5
def initialize
  @index = {}
  @childs_ids = {}
end

Public Instance Methods

call(fragments) click to toggle source
# File lib/umwelt/tree/fill.rb, line 10
def call(fragments)
  fragments.each do |fragment|
    add_to_index(fragment)
    register_as_child(fragment)
  end
  fill_trunk
end

Private Instance Methods

add_to_index(fragment) click to toggle source
# File lib/umwelt/tree/fill.rb, line 20
def add_to_index(fragment)
  @index[fragment.id] = fragment
end
fill_trunk() click to toggle source
# File lib/umwelt/tree/fill.rb, line 31
def fill_trunk
  Trunk.new(index: @index, childs_ids: @childs_ids)
end
register_as_child(fragment) click to toggle source
# File lib/umwelt/tree/fill.rb, line 24
def register_as_child(fragment)
  return if fragment.context_id.nil?

  @childs_ids[fragment.context_id] ||= []
  @childs_ids[fragment.context_id] << fragment.id
end