Sha256: 9d1b8f15c830370f3311c46ed12c70a446c5cc89eda72c8c0f4e2d58a31d5753

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

require "nokogiri"

module RelatonOgc
  class XMLParser < RelatonIsoBib::XMLParser
    class << self
      # Override RelatonIsoBib::XMLParser.form_xml method.
      # @param xml [String]
      # @return [RelatonOgc::OgcBibliographicItem]
      def from_xml(xml)
        doc = Nokogiri::XML(xml)
        item = doc.at "/bibitem|/bibdata"
        if item
          OgcBibliographicItem.new item_data(item)
        else
          warn "[relaton-ogc] can't find bibitem or bibdata element in the XML"
        end
      end

      private

      # Override RelatonIsoBib::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[:docsubtype] = ext.at("./docsubtype")&.text
        data
      end

      # @TODO Organization doesn't recreated
      # @param ext [Nokogiri::XML::Element]
      # @return [RelatonIsoBib::EditorialGroup]
      def fetch_editorialgroup(ext)
        eg = ext.at("./editorialgroup")
        return unless eg

        committe = eg&.at("committee")&.text
        sc = iso_subgroup eg&.at("subcommittee")
        wg = iso_subgroup eg&.at("workgroup")
        EditorialGroup.new(
          committee: committe, subcommittee: sc, workgroup: wg,
        )
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
relaton-ogc-1.1.0 lib/relaton_ogc/xml_parser.rb
relaton-ogc-1.0.1 lib/relaton_ogc/xml_parser.rb
relaton-ogc-1.0.0 lib/relaton_ogc/xml_parser.rb
relaton-ogc-0.7.3 lib/relaton_ogc/xml_parser.rb
relaton-ogc-0.7.2 lib/relaton_ogc/xml_parser.rb
relaton-ogc-0.7.1 lib/relaton_ogc/xml_parser.rb