class XmlProcessor

Constants

BROKEN_VARIABLE_PATTERN

Public Class Methods

clean_spaces_inside_variables(match) click to toggle source
# File lib/docx/xml_processor.rb, line 21
def self.clean_spaces_inside_variables(match)
    ret = match.dup
    cleaner_methods = Cleaners.methods.grep /_cleaner/
    cleaner_methods.each do |clean_method|
        ret = Cleaners.send(clean_method, ret)
    end
    puts "Returning cleaned variable: #{ret}"
    ret
end
clean_variables(document) click to toggle source
# File lib/docx/xml_processor.rb, line 6
def self.clean_variables(document)
    document.gsub(/\{\{.*?\}\}/m) do |match|
        ret = match.include?('>') ? join_variable_tags(match) : match
        ret = clean_spaces_inside_variables(ret)
        ret
    end
end
join_variable_tags(match) click to toggle source
# File lib/docx/xml_processor.rb, line 14
def self.join_variable_tags(match)
    before = match.gsub(/\<(.*)/m, '')
    inside = match.scan(/<w:t.*?>([^>]*?)<.w:t>/m).join(' ').gsub(/\s*\.\s*/, '.')
    after = match.gsub(/.*>([^>]+)$/m, "\\1")
    [before, inside, after].join(' ')
end