Sha256: 08bfdd7c3bc8dd031159e3b18a980aca0ccb1bf2f107d86e7ffb47085c7b7f99

Contents?: true

Size: 1.15 KB

Versions: 9

Compression:

Stored size: 1.15 KB

Contents

module RelatonNist
  class XMLParser < RelatonBib::XMLParser
    class << self
      def from_xml(xml)
        doc = Nokogiri::XML xml
        doc.remove_namespaces!
        nistitem = doc.at("/bibitem|/bibdata")
        if nistitem
          NistBibliographicItem.new(item_data(nistitem))
        elsif
          warn "[relaton-nist] can't find bibitem or bibdata element in the XML"
        end
      end

      private

      def item_data(nistitem)
        data = super
        ext = nistitem.at "./ext"
        return data unless ext

        data[:commentperiod] = fetch_commentperiod(ext)
        data
      end

      def fetch_status(item)
        status = item.at "./status"
        return unless status

        DocumentStatus.new(
          stage: status.at("stage")&.text,
          substage: status.at("substage")&.text,
          iteration: status.at("iteration")&.text,
        )
      end

      def fetch_commentperiod(item)
        cp = item.at "./commentperiod"
        return unless cp

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
relaton-nist-1.2.1 lib/relaton_nist/xml_parser.rb
relaton-nist-1.2.0 lib/relaton_nist/xml_parser.rb
relaton-nist-1.1.0 lib/relaton_nist/xml_parser.rb
relaton-nist-1.0.2 lib/relaton_nist/xml_parser.rb
relaton-nist-1.0.1 lib/relaton_nist/xml_parser.rb
relaton-nist-1.0.0 lib/relaton_nist/xml_parser.rb
relaton-nist-0.9.1 lib/relaton_nist/xml_parser.rb
relaton-nist-0.9.0 lib/relaton_nist/xml_parser.rb
relaton-nist-0.8.2 lib/relaton_nist/xml_parser.rb