Module: Puree::XMLExtractor::Shared

Defined in:
lib/puree/xml_extractor/shared.rb

Overview

Shared XML extractor.

Class Method Summary collapse

Class Method Details

.external_organisation_header(nokogiri_xml_element) ⇒ Puree::Model::ExternalOrganisationHeader



10
11
12
13
14
15
16
17
18
# File 'lib/puree/xml_extractor/shared.rb', line 10

def self.external_organisation_header(nokogiri_xml_element)
  h = Puree::Model::ExternalOrganisationHeader.new
  h.uuid = nokogiri_xml_element.xpath('@uuid').text.strip
  xpath_result_name = nokogiri_xml_element.xpath('name/text')
  h.name = xpath_result_name.first.text.strip unless xpath_result_name.empty?
  xpath_result_type = nokogiri_xml_element.xpath('type/term/text')
  h.type = xpath_result_type.first.text.strip unless xpath_result_type.empty?
  h.data? ? h : nil
end

.external_organisation_multi_header(nokogiri_xml_nodeset) ⇒ Array<Puree::Model::ExternalOrganisationHeader>



21
22
23
24
25
26
27
28
# File 'lib/puree/xml_extractor/shared.rb', line 21

def self.external_organisation_multi_header(nokogiri_xml_nodeset)
  data = []
  nokogiri_xml_nodeset.each do |i|
    header =  external_organisation_header(i)
    data << header if header
  end
  data.uniq { |d| d.uuid }
end

.organisation_header(nokogiri_xml_element) ⇒ Puree::Model::OrganisationalUnitHeader



31
32
33
34
35
36
37
38
39
# File 'lib/puree/xml_extractor/shared.rb', line 31

def self.organisation_header(nokogiri_xml_element)
  h = Puree::Model::OrganisationalUnitHeader.new
  h.uuid = nokogiri_xml_element.xpath('@uuid').text.strip
  xpath_result_name = nokogiri_xml_element.xpath('name/text')
  h.name = xpath_result_name.first.text.strip unless xpath_result_name.empty?
  xpath_result_type = nokogiri_xml_element.xpath('type/term/text')
  h.type = xpath_result_type.first.text.strip unless xpath_result_type.empty?
  h.data? ? h : nil
end

.organisation_multi_header(nokogiri_xml_nodeset) ⇒ Array<Puree::Model::OrganisationalUnitHeader>



42
43
44
45
46
47
48
49
# File 'lib/puree/xml_extractor/shared.rb', line 42

def self.organisation_multi_header(nokogiri_xml_nodeset)
  data = []
  nokogiri_xml_nodeset.each do |i|
    header = organisation_header(i)
    data << header if header
  end
  data.uniq { |d| d.uuid }
end