Sha256: f813f173183055d89ea823c06e902dbbd00f1dd88dd67655f0e73837f9bdd73c

Contents?: true

Size: 537 Bytes

Versions: 4

Compression:

Stored size: 537 Bytes

Contents

require 'rexml/document'

# Discovers values in the format <key>value, which may occur in XML/HTML.
# XML attribute values are already handled using the basic ValueDiscoverer,
# since they match the `key="value"` format that it handles.
class Carwash::XmlValueDiscoverer < Struct.new(:key)
  def discover(line)
    line.scan(%r{[^/]#{key}>(?:([^<]+)|<!\[CDATA\[(.*?)\]\])}i)
      .map(&:compact)
      .flatten(1)
      .map { |val| unescape_value(val) }
  end

  def unescape_value(value)
    REXML::Text::unnormalize(value)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
carwash-1.0.7 lib/carwash/xml_value_discoverer.rb
carwash-1.0.6 lib/carwash/xml_value_discoverer.rb
carwash-1.0.5 lib/carwash/xml_value_discoverer.rb
carwash-1.0.0 lib/carwash/xml_value_discoverer.rb