class Calendav::Parsers::ResponseXML

Attributes

namespaces[R]
raw[R]

Public Class Methods

call(...) click to toggle source
# File lib/calendav/parsers/response_xml.rb, line 10
def self.call(...)
  new(...).call
end
new(raw, namespaces = NAMESPACES) click to toggle source
# File lib/calendav/parsers/response_xml.rb, line 14
def initialize(raw, namespaces = NAMESPACES)
  @raw = raw
  @namespaces = namespaces
end

Public Instance Methods

call() click to toggle source
# File lib/calendav/parsers/response_xml.rb, line 19
def call
  return document if document.xpath("/dav:multistatus").empty?

  MultiResponse.new(document)
end

Private Instance Methods

document() click to toggle source
# File lib/calendav/parsers/response_xml.rb, line 29
def document
  @document ||= begin
    initial = parse(raw)

    namespaces.each do |key, value|
      initial.root[key] = value unless initial.namespaces[key]
    end

    parse(initial.to_xml)
  end
end
parse(string) click to toggle source
# File lib/calendav/parsers/response_xml.rb, line 41
def parse(string)
  Nokogiri::XML(string) { |config| config.strict.noblanks }
rescue Nokogiri::XML::SyntaxError => error
  raise ParsingXMLError.new(string, error)
end