Sha256: 6b786ee0b597d4b953e16dbc79de106d3aeb2d9ea0c286c3889db3f0fc43043b

Contents?: true

Size: 1.89 KB

Versions: 2

Compression:

Stored size: 1.89 KB

Contents

module Puree

  module XMLExtractor

    # Shared XML extractor.
    #
    module Shared

      # @return [Puree::Model::ExternalOrganisationHeader]
      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('names/name')
        h.name = xpath_result_name.first.text.strip unless xpath_result_name.empty?
        xpath_result_type = nokogiri_xml_element.xpath('types/type')
        h.type = xpath_result_type.first.text.strip unless xpath_result_type.empty?
        h.data? ? h : nil
      end

      # @return [Array<Puree::Model::ExternalOrganisationHeader>]
      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

      # @return [Puree::Model::OrganisationalUnitHeader]
      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('names/name')
        h.name = xpath_result_name.first.text.strip unless xpath_result_name.empty?
        xpath_result_type = nokogiri_xml_element.xpath('types/type')
        h.type = xpath_result_type.first.text.strip unless xpath_result_type.empty?
        h.data? ? h : nil
      end

      # @return [Array<Puree::Model::OrganisationalUnitHeader>]
      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

    end

  end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
puree-2.8.1 lib/puree/xml_extractor/shared.rb
puree-2.8.0 lib/puree/xml_extractor/shared.rb