Sha256: a2314ca941d4a77acef27c3515868c41d4452a1053dd054457cfe2530ab10fb9

Contents?: true

Size: 1.72 KB

Versions: 4

Compression:

Stored size: 1.72 KB

Contents

module RelatonIho
  class XMLParser < RelatonBib::XMLParser
    class << self
      private

      # Override RelatonBib::XMLParser.item_data method.
      # @param item [Nokogiri::XML::Element]
      # @returtn [Hash]
      def item_data(item)
        data = super
        ext = item.at "./ext"
        return data unless ext

        data[:commentperiod] = fetch_commentperiond ext
        data
      end

      # @param item_hash [Hash]
      # @return [RelatonIho::IhoBibliographicItem]
      def bib_item(item_hash)
        IhoBibliographicItem.new **item_hash
      end

      # @param ext [Nokogiri::XML::Element, nil]
      # @return [RelatonIho::EditorialGroupCollection, nil]
      def fetch_editorialgroup(ext)
        return unless ext

        egs = ext.xpath("editorialgroup").map do |eg|
          grps = eg.xpath("committee|workgroup|commission").map do |ig|
            iho_group ig
          end
          EditorialGroup.new grps
        end
        EditorialGroupCollection.new egs if egs.any?
      end

      # @param ihgrp [Nokogiri::XML::Element, nil]
      # @return [RelatonIho::Committee, RelatonIho::Commission,
      #   RelatonIho::Workgroup, nil]
      def iho_group(ihgrp)
        return unless ihgrp

        klass = Object.const_get "RelatonIho::" + ihgrp.name.capitalize
        subg = iho_group ihgrp.at("./committee|./workgroup|./commission")
        klass.new ihgrp.at("abbreviation").text, ihgrp.at("name")&.text, subg
      end

      # @param ext [Nokogiri::XML::Element]
      # @return [RelatonIho::CommentPeriod, nil]
      def fetch_commentperiond(ext)
        return unless ext && (cp = ext.at "commentperiod")

        CommentPeriond.new from: cp.at("from")&.text, to: cp.at("to")&.text
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
relaton-iho-1.9.0 lib/relaton_iho/xml_parser.rb
relaton-iho-1.8.0 lib/relaton_iho/xml_parser.rb
relaton-iho-1.7.2 lib/relaton_iho/xml_parser.rb
relaton-iho-1.7.1 lib/relaton_iho/xml_parser.rb