Sha256: 44e3389f21ff881df24b11ea2dd9ca9ab95e3c6a5f0eac63cd773b7d71c9c84f

Contents?: true

Size: 823 Bytes

Versions: 4

Compression:

Stored size: 823 Bytes

Contents

module RelatonW3c
  class XMLParser < RelatonBib::XMLParser
    class << self
      # @param xml [String]
      # @return [RelatonW3c::W3cBibliographicItem, NilClass]
      def from_xml(xml)
        doc = Nokogiri::XML xml
        doc.remove_namespaces!
        item = doc.at("/bibitem|/bibdata")
        if item
          W3cBibliographicItem.new(item_data(item))
        else
          warn "[relaton-w3c] can't find bibitem or bibdata element in the XML"
        end
      end

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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
relaton-w3c-1.0.2 lib/relaton_w3c/xml_parser.rb
relaton-w3c-1.0.1 lib/relaton_w3c/xml_parser.rb
relaton-w3c-1.0.0 lib/relaton_w3c/xml_parser.rb
relaton-w3c-0.1.0 lib/relaton_w3c/xml_parser.rb