lib/relaton_iana/data_fetcher.rb in relaton-iana-1.14.2 vs lib/relaton_iana/data_fetcher.rb in relaton-iana-1.14.3

- old
+ new

@@ -1,9 +1,7 @@ module RelatonIana class DataFetcher - SOURCE = "https://raw.githubusercontent.com/ietf-ribose/iana-registries/main/".freeze - # # Data fetcher initializer # # @param [String] output directory to save files # @param [String] format format of output files (xml, yaml, bibxml) @@ -11,10 +9,11 @@ def initialize(output, format) @output = output @format = format @ext = format.sub(/^bib/, "") @files = [] + @index = Relaton::Index.find_or_create :IANA, file: "index-v1.yaml" end # # Initialize fetcher and run fetch # @@ -39,10 +38,11 @@ content = File.read file, encoding: "UTF-8" parse(content) if content.include? "<registry" rescue StandardError => e warn "Error: #{e.message}. File: #{file}" end + @index.save end def parse(content) xml = Nokogiri::XML(content) registry = xml.at("/xmlns:registry") @@ -68,9 +68,10 @@ if @files.include? file warn "File #{file} already exists. Document: #{bib.docnumber}" else @files << file end + @index.add_or_update bib.docnumber, file File.write file, c, encoding: "UTF-8" end # # Generate file name