# File lib/yadis/xrds.rb, line 47 def XRDS._load(s) XRDS.new(s) end
# File lib/yadis/xrds.rb, line 43 def _dump(depth) return @xml_text end
# File lib/yadis/xrds.rb, line 51 def parse_xml(xml_text) begin xml = @xml = REXML::Document.new(xml_text) rescue raise ArgumentError, "Can't parse XRDS" end if xml.root.nil? raise ArgumentError, "No document root" end xrd = self.last_xrd(xml.root) raise ArgumentError, "No XRD Elements found" if xrd.nil? @services = {} # keyed by [service_priority, uri_priority] REXML::XPath.each(xrd, 'xrdns:Service', @@namespaces) do |s| _create_services(s) end REXML::XPath.each(xrd, 'xrdns:CanonicalID', @@namespaces) do |c| canonical_id = c.text.strip if canonical_id.length > 0 self.services.each {|s| s.canonical_id = canonical_id} end end end
Returns an Array of ServiceEndpoint objects, sorted by priority. Highest priority is at element 0.
# File lib/yadis/xrds.rb, line 82 def services s = [] @services.keys.sort.each do |key| services_list = @services[key].dup # randomize services with the same priority while services_list.length > 0 s << services_list.delete_at((rand * services_list.length).to_i) end end return s end