Module: Resync::XML

Defined in:
lib/resync/xml.rb

Overview

Helper methods and modules related to reading and writing XML.

Defined Under Namespace

Classes: ChangeNode, ChangefreqNode, HashCodesNode, MimeTypeNode, TimeNode, UriNode

Class Method Summary collapse

Class Method Details

.element(xml) ⇒ REXML::Element

Extracts a REXML::Element from the specified object.

Parameters:

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

    A string or IO-like object containing an XML document (with or without XML declaration), or an XML document, or an XML element.

Returns:

  • (REXML::Element)

    the root element of the document, or the element itself if xml is already an element.



28
29
30
31
32
33
34
35
36
37
38
# File 'lib/resync/xml.rb', line 28

def self.element(xml)
  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
end

.to_uri(url) ⇒ Object

Ensures that the provided value is a URI, parsing it if necessary.

Parameters:

  • url (URI, String)

    the URI.

Raises:

  • (URI::InvalidURIError)

    if url cannot be converted to a URI.



16
17
18
19
# File 'lib/resync/xml.rb', line 16

def self.to_uri(url)
  return nil unless url
  (url.is_a? URI) ? url : URI.parse(url)
end