Sha256: 736fd9739669b64b7071081856a8f59c0fafe70f28a0400eff8a59fae2fef92b

Contents?: true

Size: 1.15 KB

Versions: 15

Compression:

Stored size: 1.15 KB

Contents

require "nokogiri"

module RelatonGb
  class XMLParser < RelatonIsoBib::XMLParser
    class << self
      private

      # override RelatonBib::BibliographicItem.bib_item method
      # @param item_hash [Hash]
      # @return [RelatonGb::GbBibliographicItem]
      def bib_item(item_hash)
        GbBibliographicItem.new(**item_hash)
      end

      def item_data(gbitem)
        data = super
        data[:committee] = fetch_committee gbitem
        data[:gbtype] = fetch_gbtype gbitem
        data[:ccs] = fetch_ccs gbitem
        data[:plannumber] = gbitem.at("./plannumber")&.text
        data
      end

      def fetch_committee(doc)
        committee = doc.at "./ext/gbcommittee"
        return nil unless committee

        { type: committee[:type], name: committee.text }
      end

      def fetch_ccs(doc)
        doc.xpath("./ext/ccs/code").map &:text
      end

      def fetch_gbtype(doc)
        gbtype = doc.at "./ext/gbtype"
        {
          scope: gbtype&.at("gbscope")&.text,
          prefix: gbtype&.at("gbprefix")&.text,
          mandate: gbtype&.at("gbmandate")&.text,
          topic: gbtype&.at("gbtopic")&.text,
        }
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
relaton-gb-1.18.4 lib/relaton_gb/xml_parser.rb
relaton-gb-1.18.3 lib/relaton_gb/xml_parser.rb
relaton-gb-1.18.2 lib/relaton_gb/xml_parser.rb
relaton-gb-1.18.1 lib/relaton_gb/xml_parser.rb
relaton-gb-1.18.0 lib/relaton_gb/xml_parser.rb
relaton-gb-1.17.0 lib/relaton_gb/xml_parser.rb
relaton-gb-1.16.3 lib/relaton_gb/xml_parser.rb
relaton-gb-1.16.2 lib/relaton_gb/xml_parser.rb
relaton-gb-1.16.1 lib/relaton_gb/xml_parser.rb
relaton-gb-1.16.0 lib/relaton_gb/xml_parser.rb
relaton-gb-1.14.0 lib/relaton_gb/xml_parser.rb
relaton-gb-1.13.0 lib/relaton_gb/xml_parser.rb
relaton-gb-1.12.1 lib/relaton_gb/xml_parser.rb
relaton-gb-1.12.0 lib/relaton_gb/xml_parser.rb
relaton-gb-1.11.0 lib/relaton_gb/xml_parser.rb