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.is_a?(::REXML::Element) then Element.new(duck)
    when duck.is_a?(::String)    then new(::REXML::Document.new(duck).root)
    when duck.respond_to?(:read) then new(duck.read)
    when duck.respond_to?(:to_s) then new(duck.to_s)
    else raise "Don't know how to deal with '#{duck.class}' object"
  end
end