Sha256: 5d9a4fb36fa478de73c8f6af78f27cfb73d049272d3a050dc668545220833949

Contents?: true

Size: 1.45 KB

Versions: 23

Compression:

Stored size: 1.45 KB

Contents

require "nokogiri"

module RelatonItu
  class XMLParser < RelatonIsoBib::XMLParser
    class << self
      # Override RelatonIsoBib::XMLParser.form_xml method.
      # @param xml [String]
      # @return [RelatonItu::ItuBibliographicItem]
      def from_xml(xml)
        doc = Nokogiri::XML(xml)
        ituitem = doc.at "/bibitem|/bibdata"
        ItuBibliographicItem.new item_data(ituitem)
      end

      private

      # @param ext [Nokogiri::XML::Element]
      # @return [RelatonItu::EditorialGroup]
      def fetch_editorialgroup(ext)
        eg = ext.at("./editorialgroup")
        return unless eg

        EditorialGroup.new(
          bureau: eg.at("bureau")&.text,
          group: itugroup(eg.at("group")),
          subgroup: itugroup(eg.at("subgroup")),
          workgroup: itugroup(eg.at("workgroup")),
        )
      end

      # @param com [Nokogiri::XML::Element]
      # @return [RelatonItu::ItuGroup]
      def itugroup(group)
        return unless group

        ItuGroup.new(
          type: group[:type],
          name: group.at("name").text,
          acronym: group.at("acronym").text,
          period: itugroupperiod(group.at("period")),
        )
      end

      # @param com [Nokogiri::XML::Element]
      # @return [RelatonItu::ItuGroup::Period]
      def itugroupperiod(period)
        return until period

        ItuGroup::Period.new(
          start: period.at("start").text, finish: period.at("end")&.text,
        )
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
relaton-itu-0.8.0 lib/relaton_itu/xml_parser.rb
relaton-itu-0.7.0 lib/relaton_itu/xml_parser.rb
relaton-itu-0.6.0 lib/relaton_itu/xml_parser.rb
relaton-itu-0.5.1 lib/relaton_itu/xml_parser.rb
relaton-itu-0.5.0 lib/relaton_itu/xml_parser.rb
relaton-itu-0.4.1 lib/relaton_itu/xml_parser.rb
relaton-itu-0.4.0 lib/relaton_itu/xml_parser.rb
relaton-itu-0.3.11 lib/relaton_itu/xml_parser.rb
relaton-itu-0.3.10 lib/relaton_itu/xml_parser.rb
relaton-itu-0.3.9 lib/relaton_itu/xml_parser.rb
relaton-itu-0.3.8 lib/relaton_itu/xml_parser.rb
relaton-itu-0.3.7 lib/relaton_itu/xml_parser.rb
relaton-itu-0.3.6 lib/relaton_itu/xml_parser.rb
relaton-itu-0.3.5 lib/relaton_itu/xml_parser.rb
relaton-itu-0.3.4 lib/relaton_itu/xml_parser.rb
relaton-itu-0.3.3 lib/relaton_itu/xml_parser.rb
relaton-itu-0.3.2 lib/relaton_itu/xml_parser.rb
relaton-itu-0.3.1 lib/relaton_itu/xml_parser.rb
relaton-itu-0.3.0 lib/relaton_itu/xml_parser.rb
relaton-itu-0.2.3 lib/relaton_itu/xml_parser.rb