Module: Resync::XML
- Defined in:
- lib/resync/xml.rb
Overview
Helper methods and modules related to reading and writing XML.
Defined Under Namespace
Classes: HashCodesNode
Class Method Summary collapse
-
.element(xml) ⇒ REXML::Element
Extracts a
REXML::Elementfrom the specified object. -
.to_uri(url) ⇒ Object
Ensures that the provided value is a
URI, parsing it if necessary.
Class Method Details
.element(xml) ⇒ REXML::Element
Extracts a REXML::Element from the specified object.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/resync/xml.rb', line 33 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.
19 20 21 22 23 24 |
# File 'lib/resync/xml.rb', line 19 def self.to_uri(url) return nil unless url return url if url.is_a? URI stripped = url.respond_to?(:strip) ? url.strip : url.to_s.strip URI.parse(stripped) end |