Sha256: 3ee6104f52d3c866f84ccfe183d5fd8e0b0895c3e21cbb0db5c0eab1ffd5cc31

Contents?: true

Size: 1.72 KB

Versions: 16

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

16 entries across 16 versions & 1 rubygems

Version Path
relaton-iho-1.18.0 lib/relaton_iho/xml_parser.rb
relaton-iho-1.17.0 lib/relaton_iho/xml_parser.rb
relaton-iho-1.16.2 lib/relaton_iho/xml_parser.rb
relaton-iho-1.16.1 lib/relaton_iho/xml_parser.rb
relaton-iho-1.16.0 lib/relaton_iho/xml_parser.rb
relaton-iho-1.14.3 lib/relaton_iho/xml_parser.rb
relaton-iho-1.14.2 lib/relaton_iho/xml_parser.rb
relaton-iho-1.14.1 lib/relaton_iho/xml_parser.rb
relaton-iho-1.14.0 lib/relaton_iho/xml_parser.rb
relaton-iho-1.13.0 lib/relaton_iho/xml_parser.rb
relaton-iho-1.12.1 lib/relaton_iho/xml_parser.rb
relaton-iho-1.12.0 lib/relaton_iho/xml_parser.rb
relaton-iho-1.11.0 lib/relaton_iho/xml_parser.rb
relaton-iho-1.10.2 lib/relaton_iho/xml_parser.rb
relaton-iho-1.10.1 lib/relaton_iho/xml_parser.rb
relaton-iho-1.10.0 lib/relaton_iho/xml_parser.rb