Module: OEmbed::Formatter::XML::Backends::XmlSimple

Extended by:
XmlSimple
Included in:
XmlSimple
Defined in:
lib/oembed/formatter/xml/backends/xmlsimple.rb

Overview

Use the xml-simple gem to parse XML values.

Instance Method Summary collapse

Instance Method Details

#decode(xml) ⇒ Object

Parses an XML string or IO and convert it into an object.



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/oembed/formatter/xml/backends/xmlsimple.rb', line 13

def decode(xml)
  if !xml.respond_to?(:read)
    xml = StringIO.new(xml)
  end
  ::XmlSimple.xml_in(xml, 'ForceArray'=>false)
rescue
  case $!
  when parse_error
    raise $!
  else
    raise parse_error, "Couldn't parse the given document."
  end  
end

#decode_fail_msgObject



27
28
29
# File 'lib/oembed/formatter/xml/backends/xmlsimple.rb', line 27

def decode_fail_msg
  "The version of the xml-simple library you have installed isn't parsing XML like ruby-oembed expected."
end

#parse_errorObject



31
32
33
# File 'lib/oembed/formatter/xml/backends/xmlsimple.rb', line 31

def parse_error
  ::ArgumentError
end