-
Notifications
You must be signed in to change notification settings - Fork 70
/
rexml.rb
36 lines (32 loc) · 1 KB
/
rexml.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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
# Parses an XML string or IO and convert it into an object
def decode(xml)
xml = StringIO.new(xml) unless xml.respond_to?(:read)
obj = {}
doc = ::REXML::Document.new(xml)
doc.elements[1].elements.each do |el|
obj[el.name] = el.text
end
obj
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
public_instance_methods.each { |method| module_function(method) }
end
end
end
end
end