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
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/protocol/caldav/filter/parser.rb', line 35 def parse_addressbook(xml_string) return nil if xml_string.nil? || xml_string.strip.empty? doc = REXML::Document.new(xml_string) ns = { 'cr' => CARDDAV_NS } filter_el = REXML::XPath.first(doc, './/cr:filter', ns) return nil unless 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) rescue REXML::ParseException => e raise ParseError, "Malformed XML: #{e.}" end |
.parse_calendar(xml_string) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/protocol/caldav/filter/parser.rb', line 18 def parse_calendar(xml_string) return nil if xml_string.nil? || xml_string.strip.empty? doc = REXML::Document.new(xml_string) ns = { 'c' => CALDAV_NS } filter_el = REXML::XPath.first(doc, './/c:filter', ns) return nil unless filter_el comp_el = REXML::XPath.first(filter_el, 'c:comp-filter', ns) return nil unless comp_el parse_comp_filter(comp_el, ns) rescue REXML::ParseException => e raise ParseError, "Malformed XML: #{e.}" end |