Class: OEmbed::Formatters::RubyXML
- Inherits:
-
Object
- Object
- OEmbed::Formatters::RubyXML
- Defined in:
- lib/oembed_links/formatters/ruby_xml.rb
Instance Method Summary collapse
-
#format(txt) ⇒ Object
This is an extremely naive XML doc to hash formatter.
- #name ⇒ Object
Instance Method Details
#format(txt) ⇒ Object
This is an extremely naive XML doc to hash formatter. Cases like arrays represented in XML will not work; only strings, ints and floats will be converted.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/oembed_links/formatters/ruby_xml.rb', line 16 def format(txt) doc = ::REXML::Document.new(txt) h = { } doc.elements.each("/oembed/*") do |elem| c = elem.text if c =~ /^[0-9]+$/ c = c.to_i elsif c=~ /^[0-9]+\.[0-9]+$/ c = c.to_f end h[elem.name.strip] = c end return h end |
#name ⇒ Object
8 9 10 |
# File 'lib/oembed_links/formatters/ruby_xml.rb', line 8 def name "xml" end |