class ArticleFixtureGen::Data::BuildFragmentList

Assembles a “fragment list”, a list of objects associating a string as found in a DOM leaf text node with the DOM position of that leaf node relative to a specified parent node and initial position. The default initial position, `[]`, indicates that the parent node is the root node of a DOM tree known to the caller.

Public Class Methods

call(parent_node:, position: []) click to toggle source
# File lib/article_fixture_gen/data/build_fragment_list.rb, line 13
def self.call(parent_node:, position: [])
  BuildFragmentList.new.call(parent_node, position)
end

Public Instance Methods

call(parent_node, position) click to toggle source
# File lib/article_fixture_gen/data/build_fragment_list.rb, line 17
def call(parent_node, position)
  ret = []
  Internals.with_each_child_of(parent_node) do |node, index|
    ret += add_items_for(node, index, position)
  end
  ret
end

Private Instance Methods

add_items_for(node, index, position) click to toggle source
# File lib/article_fixture_gen/data/build_fragment_list.rb, line 27
def add_items_for(node, index, position)
  item_pos = Internals.position_with(position, index)
  return call(node, item_pos) if Internals.node?(node)
  Internals.item_with(item_pos, node)
end