Module: XMLObject::Adapters::REXML

Defined in:
lib/xml-object/adapters/rexml.rb

Defined Under Namespace

Classes: Element

Class Method Summary collapse

Class Method Details

.new(duck) ⇒ Object

Can take a String of XML data, or anything that responds to either read or to_s.



7
8
9
10
11
12
13
14
15
# File 'lib/xml-object/adapters/rexml.rb', line 7

def self.new(duck)
  case
    when duck.respond_to?(:read)
      then Element.new(::REXML::Document.new(duck.read).root)
    when duck.respond_to?(:to_s)
      then Element.new(::REXML::Document.new(duck.to_s).root)
    else raise "Don't know how to deal with '#{duck.class}' object"
  end
end