Module: XMLObject::Adapters::LibXML
- Defined in:
- lib/xml-object/adapters/libxml.rb
Defined Under Namespace
Classes: Element
Class Method Summary collapse
-
.new(duck) ⇒ Object
Can take a String of XML data, or anything that responds to either
read
orto_s
.
Class Method Details
.new(duck) ⇒ Object
Can take a String of XML data, or anything that responds to either read
or to_s
.
6 7 8 9 10 11 12 13 14 |
# File 'lib/xml-object/adapters/libxml.rb', line 6 def self.new(duck) case when duck.respond_to?(:read) then Element.new(::LibXML::XML::Parser.string(duck.read).parse.root) when duck.respond_to?(:to_s) then Element.new(::LibXML::XML::Parser.string(duck.to_s).parse.root) else raise "Don't know how to deal with '#{duck.class}' object" end end |