Module: XML::Mapping::ClassMethods

Defined in:
lib/xml/mapping_extensions.rb

Instance Method Summary collapse

Instance Method Details

#parse_xml(xml) ⇒ Object

Create a new instance of this class from the XML contained in xml, which can be a string, REXML document, or REXML element

Parameters:

  • xml (String, REXML::Document, REXML::Element)

Returns:

  • (Object)

    an instance of this class.



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/xml/mapping_extensions.rb', line 56

def parse_xml(xml)
  element = case xml
            when REXML::Document
              xml.root
            when REXML::Element
              xml
            else
              fail ArgumentError, "Unexpected argument type; expected XML document, String, or IO source, was #{xml.class}" unless can_parse(xml)
              REXML::Document.new(xml).root
            end
  load_from_xml(element)
end