Skip to content

Commit

Permalink
fix issue #76
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew2net committed Apr 6, 2022
1 parent ecfa4aa commit 3627060
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
40 changes: 32 additions & 8 deletions lib/relaton_ietf/data_fetcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,44 @@ def fetch_ieft_internet_drafts # rubocop:disable Metrics/MethodLength
# @param [Array<String>] 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 = /(?<id>draft-.+)-(?<ver>\d{2})\.#{@ext}$/.match file
match = /(?<series>draft-.+)-(?<ver>\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<String>] 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
#
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions spec/relaton_ietf/data_fetcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3627060

Please sign in to comment.