Sha256: 2ac32c57454f750a7c6a875855fa8471438cdd34bf125b86c6316362078c1a11
Contents?: true
Size: 1016 Bytes
Versions: 3
Compression:
Stored size: 1016 Bytes
Contents
require_relative 'cleaners' class XmlProcessor BROKEN_VARIABLE_PATTERN = "<w:t>([^\#^<^>]*?)#([^\#^<^>]*?)<\/w:t>" 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 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 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 end # {{% devedor[:pessoa_fisica][:cedula_identidade] %}},
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
docx-builder-0.1.13 | lib/docx/xml_processor.rb |
docx-builder-0.1.11 | lib/docx/xml_processor.rb |
docx-builder-0.1.8 | lib/docx/xml_processor.rb |