Class: DiasporaFederation::Parsers::XmlParser

Inherits:
BaseParser
  • Object
show all
Defined in:
lib/diaspora_federation/parsers/xml_parser.rb

Overview

This is a parser of XML serialized object. Explanations about the XML data format can be found here.

Direct Known Subclasses

RelayableXmlParser

Instance Method Summary collapse

Methods inherited from BaseParser

#initialize

Constructor Details

This class inherits a constructor from DiasporaFederation::Parsers::BaseParser

Instance Method Details

#parse(root_node) ⇒ Array[1]

Returns comprehensive data for an entity instantiation

Parameters:

  • root_node (Nokogiri::XML::Element)

    root XML node of the XML representation of the entity

Returns:

  • (Array[1])

    comprehensive data for an entity instantiation

See Also:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/diaspora_federation/parsers/xml_parser.rb', line 12

def parse(root_node)
  from_xml_sanity_validation(root_node)

  hash = root_node.element_children.map {|child|
    xml_name = child.name
    property = entity_type.find_property_for_xml_name(xml_name)
    if property
      type = class_properties[property]
      value = parse_element_from_node(xml_name, type, root_node)
      [property, value]
    else
      [xml_name, child.text]
    end
  }.to_h

  [hash]
end