module Resync::XMLParser
Parses ResourceSync XML
documents and returns appropriate objects.
Constants
- CAPABILITY_ATTRIBUTE
- ROOT_TYPES
The list of parseable types, organized by
XML
mapping.
Public Class Methods
parse(xml)
click to toggle source
Parses the specified ResourceSync document and returns the appropriate object based on the capability
attribute of the root element's metadata (i.e. +<rs:md>+).
@param xml [String, REXML::Document, REXML::Element] a ResourceSync XML
document
(or its root element)
# File lib/resync/xml_parser.rb, line 35 def self.parse(xml) root_element = XML.element(xml) mapping = root_element.name == 'sitemapindex' ? :sitemapindex : :_default root_type = find_root_type(ROOT_TYPES[mapping], root_element) root_type.load_from_xml(root_element, mapping: mapping) end
Private Class Methods
capability_attribute_for(root_element)
click to toggle source
# File lib/resync/xml_parser.rb, line 59 def self.capability_attribute_for(root_element) capability_attr = REXML::XPath.first(root_element, CAPABILITY_ATTRIBUTE) raise ArgumentError, "unable to identify capability of root element in #{root_element}" unless capability_attr capability_attr end
capability_for(root_element)
click to toggle source
# File lib/resync/xml_parser.rb, line 51 def self.capability_for(root_element) capability = capability_attribute_for(root_element).value raise ArgumentError, "unable to identify capability of root element in #{root_element}" unless capability capability end
find_root_type(types, root_element)
click to toggle source
# File lib/resync/xml_parser.rb, line 42 def self.find_root_type(types, root_element) capability = capability_for(root_element) root_type = types.find { |t| t::CAPABILITY == capability } raise ArgumentError, "no mapped type for capability '#{capability}'" unless root_type root_type end