Class: OEmbed::Formatters::HpricotXML

Inherits:
Object
  • Object
show all
Defined in:
lib/oembed_links/formatters/hpricot_xml.rb

Instance Method Summary collapse

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.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/oembed_links/formatters/hpricot_xml.rb', line 17

def format(txt)
  doc = ::Hpricot.XML(txt)
  h = { }
  (doc/"/oembed/*").each do |elem|
    if elem.is_a? Hpricot::Elem
      c = elem.innerHTML
      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
  end
  return h
end

#nameObject



7
8
9
# File 'lib/oembed_links/formatters/hpricot_xml.rb', line 7

def name
  "xml"
end