Sha256: bc0575232796897078e15be184a64d0a1b0370bf279527146c3fc18cd9cfd901

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.4 lib/carwash/xml_value_discoverer.rb
carwash-1.0.3 lib/carwash/xml_value_discoverer.rb
carwash-1.0.2 lib/carwash/xml_value_discoverer.rb
carwash-1.0.1 lib/carwash/xml_value_discoverer.rb