Class: Tilia::Dav::Xml::Element::Prop

Inherits:
Object
  • Object
show all
Includes:
Xml::XmlDeserializable
Defined in:
lib/tilia/dav/xml/element/prop.rb

Overview

This class is responsible for decoding the DAV:prop element as it appears in DAV:property-update.

This class doesn’t return an instance of itself. It just returns a key.value array.

Class Method Summary collapse

Class Method Details

.xml_deserialize(reader) ⇒ Object

The deserialize method is called during xml parsing.

This method is called statictly, this is because in theory this method may be used as a type of constructor, or factory method.

Often you want to return an instance of the current class, but you are free to return other data as well.

You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop.

If you just want to skip parsing for this element altogether, you can just call reader.next

reader.parse_inner_tree will parse the entire sub-tree, and advance to the next element.

Parameters:

  • Reader

    reader

Returns:

  • mixed



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/tilia/dav/xml/element/prop.rb', line 32

def self.xml_deserialize(reader)
  # If there's no children, we don't do anything.
  if reader.empty_element?
    reader.next
    return {}
  end

  values = {}

  reader.read
  loop do
    if reader.node_type == ::LibXML::XML::Reader::TYPE_ELEMENT
      clark = reader.clark
      values[clark] = parse_current_element(reader)['value']
    else
      reader.read
    end
    break unless reader.node_type != ::LibXML::XML::Reader::TYPE_END_ELEMENT
  end

  reader.read
  values
end