class Paramedic::XMLMasseuse

Attributes

escape_tags[R]
xml[R]

Public Class Methods

new(xml, opts={}) click to toggle source
# File lib/paramedic/xml_masseuse.rb, line 6
def initialize(xml, opts={})
  @xml = xml
  @escape_tags = opts.fetch(:escape_tags, [])
end

Public Instance Methods

to_xml() click to toggle source
# File lib/paramedic/xml_masseuse.rb, line 11
def to_xml
  strip_tag_spacing(
    escape_specified_tags(
      Nokogiri::XML(remove_naked_ampersands(xml), &:noblanks)
    )
  )
end

Private Instance Methods

escape_specified_tags(xml_document) click to toggle source
# File lib/paramedic/xml_masseuse.rb, line 25
def escape_specified_tags(xml_document)
  escape_tags.each do |escape_tag|
    xml_document.css(escape_tag).each do |element|
      strip_tag_spacing(element)
      element.inner_html = CGI.escape_html(element.inner_html)
    end
  end

  xml_document
end
remove_naked_ampersands(text) click to toggle source
# File lib/paramedic/xml_masseuse.rb, line 21
def remove_naked_ampersands(text)
  text.gsub('&', '&')
end
strip_tag_spacing(xml_document) click to toggle source
# File lib/paramedic/xml_masseuse.rb, line 36
def strip_tag_spacing(xml_document)
  xml_document.to_xml(
    save_with: Nokogiri::XML::Node::SaveOptions::AS_XML |
      Nokogiri::XML::Node::SaveOptions::NO_EMPTY_TAGS
  )
end