Sha256: 6e43e4c0d002fd0fa9aef5ea9c85d3a3026a450bc81e9f399056f8db0726707e
Contents?: true
Size: 1.17 KB
Versions: 25
Compression:
Stored size: 1.17 KB
Contents
# Unlike other backends, require REXML if it's not already loaded require 'rexml/document' unless defined?(REXML) module OEmbed module Formatter module XML module Backends # Use the REXML library, part of the standard library, to parse XML values. module REXML extend self # Parses an XML string or IO and convert it into an object def decode(xml) if !xml.respond_to?(:read) xml = StringIO.new(xml) end obj = {} doc = ::REXML::Document.new(xml) doc.elements[1].elements.each do |el| obj[el.name] = el.text end obj rescue case $! when parse_error raise $! else raise parse_error, "Couldn't parse the given document." end end def decode_fail_msg "The version of the REXML library you have installed isn't parsing XML like ruby-oembed expected." end def parse_error ::REXML::ParseException end end end end end end
Version data entries
25 entries across 25 versions & 2 rubygems