class Docx::NodesToFix

Attributes

current_node[RW]
node_list[RW]
value[RW]

Public Class Methods

new() click to toggle source
# File lib/docx/nodes_to_fix.rb, line 4
def initialize
  forget
end

Public Instance Methods

fix() click to toggle source
# File lib/docx/nodes_to_fix.rb, line 24
def fix
  @node_list.each do |obj|
    node = obj[:node]
    range = obj[:range]
    new_val = node.value
    new_val[range] = value.to_s || ''
    node.value = new_val
    if new_val =~ /^\s+/ && node.parent
      node.parent.add_attribute('xml:space', 'preserve')
    end
    self.value = nil
  end
end
forget() click to toggle source
# File lib/docx/nodes_to_fix.rb, line 8
def forget
  @current_node = nil
  @node_list = []
  @value = ''
end
remember(node, index) click to toggle source
# File lib/docx/nodes_to_fix.rb, line 14
def remember(node, index)
  new_node = current_node.nil? || current_node != node
  if new_node
    @current_node = node
    @node_list << {:node => node, :range => index..index}
  else
    @node_list.last[:range] = (node_list.last[:range].min)..index
  end
end