class ArticleFixtureGen::Data::ReplaceChildNodesUsingNewChild

Replaces the (INTERNAL!) list of child nodes of an element with a list generated elsewhere (that replaces a single text node with two text nodes separated by a new element).

Attributes

element[R]
new_el[R]
target_entry[R]

Public Class Methods

call(parent_node, target_entry, new_el) click to toggle source
# File lib/article_fixture_gen/data/replace_child_nodes_using_new_child.rb, line 12
def self.call(parent_node, target_entry, new_el)
  new(parent_node, target_entry, new_el).call
end
new(parent_node, target_entry, new_el) click to toggle source
# File lib/article_fixture_gen/data/replace_child_nodes_using_new_child.rb, line 22
def initialize(parent_node, target_entry, new_el)
  @element = ParentElementFor.call(parent_node, target_entry.dom_position)
  @target_entry = target_entry
  @new_el = new_el
  self
end

Public Instance Methods

call() click to toggle source
# File lib/article_fixture_gen/data/replace_child_nodes_using_new_child.rb, line 16
def call
  element.instance_variable_set :@nodes, nodes
end

Private Instance Methods

leading_node_indexes() click to toggle source
# File lib/article_fixture_gen/data/replace_child_nodes_using_new_child.rb, line 37
def leading_node_indexes
  0...node_index
end
leading_nodes() click to toggle source
# File lib/article_fixture_gen/data/replace_child_nodes_using_new_child.rb, line 33
def leading_nodes
  element.nodes[leading_node_indexes]
end
node_index() click to toggle source
# File lib/article_fixture_gen/data/replace_child_nodes_using_new_child.rb, line 41
def node_index
  target_entry.dom_position.last
end
nodes() click to toggle source
# File lib/article_fixture_gen/data/replace_child_nodes_using_new_child.rb, line 45
def nodes
  parts = SplitTextAtTargetWord.call(element, target_entry)
  replacement_nodes_for(parts)
end
parts_and_element(parts) click to toggle source
# File lib/article_fixture_gen/data/replace_child_nodes_using_new_child.rb, line 50
def parts_and_element(parts)
  parts.insert 1, new_el
end
replacement_nodes_for(parts) click to toggle source
# File lib/article_fixture_gen/data/replace_child_nodes_using_new_child.rb, line 54
def replacement_nodes_for(parts)
  [leading_nodes, parts_and_element(parts), trailing_nodes].flatten(1)
end
trailing_node_indexes() click to toggle source
# File lib/article_fixture_gen/data/replace_child_nodes_using_new_child.rb, line 62
def trailing_node_indexes
  node_index + 1..-1
end
trailing_nodes() click to toggle source
# File lib/article_fixture_gen/data/replace_child_nodes_using_new_child.rb, line 58
def trailing_nodes
  element.nodes[trailing_node_indexes]
end