diff --git a/lib/relaton_ietf/data_fetcher.rb b/lib/relaton_ietf/data_fetcher.rb index 8d1cf04..a9c4250 100644 --- a/lib/relaton_ietf/data_fetcher.rb +++ b/lib/relaton_ietf/data_fetcher.rb @@ -80,20 +80,44 @@ def fetch_ieft_internet_drafts # rubocop:disable Metrics/MethodLength # @param [Array] versions list of versions # def update_versions(versions) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity + series = "" + bib_versions = [] Dir["#{@output}/*.#{@ext}"].each do |file| - match = /(?draft-.+)-(?\d{2})\.#{@ext}$/.match file + match = /(?draft-.+)-(?\d{2})\.#{@ext}$/.match file if match - bib = read_doc(file) - bib_versions = versions.select { |ref| ref.include? match[:id] } + if series != match[:series] + bib_versions = versions.select { |ref| ref.include? match[:series] } + create_series match[:series], bib_versions + end lv = bib_versions.select { |ref| ref.match(/\d+$/).to_s.to_i < match[:ver].to_i } hv = bib_versions.select { |ref| ref.match(/\d+$/).to_s.to_i > match[:ver].to_i } - bib.relation << version_relation(lv.last, "updates") if lv.any? - bib.relation << version_relation(hv.first, "updatedBy") if hv.any? - save_doc bib, check_duplicate: false if lv.any? || hv.any? + if lv.any? || hv.any? + bib = read_doc(file) + bib.relation << version_relation(lv.last, "updates") if lv.any? + bib.relation << version_relation(hv.first, "updatedBy") if hv.any? + save_doc bib, check_duplicate: false + end + series = match[:series] end end end + # + # Create unversioned bibliographic item + # + # @param [String] ref reference + # @param [Array] versions list of versions + # + def create_series(ref, versions) + return if versions.size < 2 + + fref = RelatonBib::FormattedRef.new content: ref + rel = versions.map do |v| + version_relation v, "includes" + end + save_doc IetfBibliographicItem.new(formattedref: fref, relation: rel) + end + # # Create bibitem relation # @@ -176,11 +200,11 @@ def save_doc(entry, check_duplicate: true) # rubocop:disable Metrics/MethodLengt # # @return [String] file name # - def file_name(entry) + def file_name(entry) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity id = if entry.respond_to? :docidentifier entry.docidentifier.detect { |i| i.type == "Internet-Draft" }&.id end - id ||= entry.docnumber + id ||= entry.docnumber || entry.formattedref.content if @source == "ietf-internet-drafts" then id.downcase! else id.upcase! end diff --git a/spec/relaton_ietf/data_fetcher_spec.rb b/spec/relaton_ietf/data_fetcher_spec.rb index 9925d71..d41c0a8 100644 --- a/spec/relaton_ietf/data_fetcher_spec.rb +++ b/spec/relaton_ietf/data_fetcher_spec.rb @@ -99,6 +99,17 @@ expect(subject).to receive(:save_doc).with(bib, check_duplicate: false) subject.update_versions ["draft-collins-pfr-01"] end + + it "create unversioned doc" do + expect(RelatonBib::FormattedRef).to receive(:new).with(content: "draft-collins-pfr").and_return(:sref) + expect(RelatonBib::FormattedRef).to receive(:new).with(content: "draft-collins-pfr-00").and_return(:fref) + expect(RelatonBib::FormattedRef).to receive(:new).with(content: "draft-collins-pfr-01").and_return(:fref) + expect(RelatonIetf::IetfBibliographicItem).to receive(:new).with(formattedref: :fref).and_return(:bibitem).twice + expect(RelatonBib::DocumentRelation).to receive(:new).with(type: "includes", bibitem: :bibitem).and_return(:rel1, :rel2) + expect(RelatonIetf::IetfBibliographicItem).to receive(:new).with(formattedref: :sref, relation:[:rel1, :rel2]).and_return(:sbib) + expect(subject).to receive(:save_doc).with(:sbib) + subject.create_series "draft-collins-pfr", ["draft-collins-pfr-00", "draft-collins-pfr-01"] + end end context "read doc" do