lib/relaton_nist/data_fetcher.rb in relaton-nist-1.10.0 vs lib/relaton_nist/data_fetcher.rb in relaton-nist-1.10.1

- old
+ new

@@ -18,10 +18,11 @@ def initialize(output, format) @output = output @format = format @ext = format.sub(/^bib/, "") + @files = [] end def parse_docid(doc) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength # case doi # when "10.6028/NBS.CIRC.12e2revjune" then doi.sub!("13e", "12e") @@ -30,11 +31,11 @@ # when "10.6028/NBS.HB.105-1r1990" then doi.sub!("105-1-1990", "105-1r1990") # when "10.6028/NIST.HB.150-10-1995" then doi.sub!(/150-10$/, "150-10-1995") # end # anchor = doi.split("/")[1..-1].join "/" [ - { type: "NIST", id: pub_id(doc) }, + { type: "NIST", id: pub_id(doc), primary: true }, { type: "DOI", id: doi(doc) }, { type: "NIST", id: anchor(doc), scope: "anchor" }, ] end @@ -189,20 +190,20 @@ # @param bib [RelatonNist::NistBibliographicItem] # def write_file(bib) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength id = bib.docidentifier[0].id.gsub(%r{[/\s:.]}, "_").upcase.sub(/^NIST_IR/, "NISTIR") file = File.join(@output, "#{id}.#{@ext}") - if File.exist? file + if @files.include? file warn "File #{file} exists. Docid: #{bib.docidentifier[0].id}" # warn "Link: #{bib.link.detect { |l| l.type == 'src' }.content}" - else - output = case @format - when "yaml" then bib.to_hash.to_yaml - when "xml" then bib.to_xml bibdata: true - else bib.send "to_#{@format}" - end - File.write file, output, encoding: "UTF-8" + else @files << file end + output = case @format + when "yaml" then bib.to_hash.to_yaml + when "xml" then bib.to_xml bibdata: true + else bib.send "to_#{@format}" + end + File.write file, output, encoding: "UTF-8" end # # Create a document instance an save it. #