Module: OEmbed::Formatter::XML::Backends::Nokogiri

Extended by:
Nokogiri
Included in:
Nokogiri
Defined in:
lib/oembed/formatter/xml/backends/nokogiri.rb

Overview

Use the nokogiri 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
26
27
# 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_msgObject


29
30
31
# 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_errorObject


33
34
35
# File 'lib/oembed/formatter/xml/backends/nokogiri.rb', line 33

def parse_error
  ::Nokogiri::XML::SyntaxError
end