module OEmbed::Formatter::XML::Backends::Nokogiri

Use the nokogiri gem to parse XML values.

Public Instance Methods

decode(xml) click to toggle source

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

# File lib/oembed/formatter/xml/backends/nokogiri.rb, line 13
def decode(xml)
  obj = {}
  doc = ::Nokogiri::XML(xml) { |config| config.strict }
  doc.root.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
decode_fail_msg() click to toggle source
# File lib/oembed/formatter/xml/backends/nokogiri.rb, line 29
def decode_fail_msg
  "The version of the nokogiri library you have installed isn't parsing XML like ruby-oembed expected."
end
parse_error() click to toggle source
# File lib/oembed/formatter/xml/backends/nokogiri.rb, line 33
def parse_error
  ::Nokogiri::XML::SyntaxError
end