Module: Protocol::Caldav::Filter::Parser

Defined in:
lib/protocol/caldav/filter/parser.rb

Constant Summary collapse

CALDAV_NS =
Constants::CALDAV_NS
CARDDAV_NS =
Constants::CARDDAV_NS

Class Method Summary collapse

Class Method Details

.parse_addressbook(xml_string) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/protocol/caldav/filter/parser.rb', line 36

def parse_addressbook(xml_string)
  if xml_string.nil? || xml_string.strip.empty?
    nil
  else
    doc = REXML::Document.new(xml_string)
    ns = { 'cr' => CARDDAV_NS }

    filter_el = REXML::XPath.first(doc, './/cr:filter', ns)

    if filter_el
      test = filter_el.attributes['test'] || 'anyof'
      prop_filters = REXML::XPath.match(filter_el, 'cr:prop-filter', ns).map do |el|
        parse_addressbook_prop_filter(el, ns)
      end

      Addressbook::Filter.new(test: test, prop_filters: prop_filters)
    end
  end
rescue REXML::ParseException => e
  raise ParseError, "Malformed XML: #{e.message}"
end

.parse_calendar(xml_string) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/protocol/caldav/filter/parser.rb', line 15

def parse_calendar(xml_string)
  if xml_string.nil? || xml_string.strip.empty?
    nil
  else
    doc = REXML::Document.new(xml_string)
    ns = { 'c' => CALDAV_NS }

    filter_el = REXML::XPath.first(doc, './/c:filter', ns)

    if filter_el
      comp_el = REXML::XPath.first(filter_el, 'c:comp-filter', ns)

      if comp_el
        parse_comp_filter(comp_el, ns)
      end
    end
  end
rescue REXML::ParseException => e
  raise ParseError, "Malformed XML: #{e.message}"
end