relaton-ietf 1.10.5 → 1.10.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2bdbf2b79c15e3a39c10694ba1ed129b825c6481f95939dfd322da43a3ea859e
4
- data.tar.gz: da2f82d0c9ec214fbef2dd229f06d8dd9ffc0099c1eededcfbfca3e3d2cebd70
3
+ metadata.gz: e52b5d3e6287636c00d9a09d115773d39156bf81f59d9db8d5168a8b4476f44b
4
+ data.tar.gz: fce58a6de2d758419f999861353b1dad1e19deb03ee52f30e901a4563a6e0750
5
5
  SHA512:
6
- metadata.gz: 2e435d1419778748b600048fd02881fa0cc32faa462fd50e95a1c837dcdd3c475ffd5f1cf0b143b1d20be38dae96dbdad3556d4b3d4954bc4a6de717da5cd0ec
7
- data.tar.gz: dcf0ce8ce233f9f29073bea10b3abc4ffb9aa70f3749c88d3961fe01e6e157616237ded93e02ac664dba7c34a89da212880e2adb3d75949d176d41ff32491123
6
+ metadata.gz: f7ce9a5b44b815388c76c231038759227937b50e4d352f5e8d1a218fdef73419c6740e7714e810d76c8dbab778c9b8d0003681e05f7ef7195e6f80cbfd58f634
7
+ data.tar.gz: 57d38a23804da9618620725efd21a232b3992a3e3a3f0d067eec9e1f4d29a5eb248c9e1cf3ad8cdbb37d6af62bf4c2d1c61afc99ec45b062ce8d9c56b12f0225
@@ -64,11 +64,93 @@ module RelatonIetf
64
64
  # Fetches ietf-internet-drafts documents
65
65
  #
66
66
  def fetch_ieft_internet_drafts # rubocop:disable Metrics/MethodLength
67
- Dir["bibxml-ids/*.xml"].each do |file|
68
- save_doc BibXMLParser.parse(File.read(file, encoding: "UTF-8"))
67
+ versions = Dir["bibxml-ids/*.xml"].each_with_object([]) do |path, vers|
68
+ file = File.basename path, ".xml"
69
+ if file.include?("D.draft-")
70
+ vers << file.sub(/^reference\.I-D\./, "")
71
+ end
72
+ save_doc BibXMLParser.parse(File.read(path, encoding: "UTF-8"))
69
73
  end
74
+ update_versions(versions) if versions.any? && @format != "bibxml"
70
75
  end
71
76
 
77
+ #
78
+ # Updates I-D's versions
79
+ #
80
+ # @param [Array<String>] versions list of versions
81
+ #
82
+ def update_versions(versions) # rubocop:disable Metrics/MethodLength, Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
83
+ series = ""
84
+ bib_versions = []
85
+ Dir["#{@output}/*.#{@ext}"].each do |file|
86
+ match = /(?<series>draft-.+)-(?<ver>\d{2})\.#{@ext}$/.match file
87
+ if match
88
+ if series != match[:series]
89
+ bib_versions = versions.select { |ref| ref.include? match[:series] }
90
+ create_series match[:series], bib_versions
91
+ end
92
+ lv = bib_versions.select { |ref| ref.match(/\d+$/).to_s.to_i < match[:ver].to_i }
93
+ hv = bib_versions.select { |ref| ref.match(/\d+$/).to_s.to_i > match[:ver].to_i }
94
+ if lv.any? || hv.any?
95
+ bib = read_doc(file)
96
+ bib.relation << version_relation(lv.last, "updates") if lv.any?
97
+ bib.relation << version_relation(hv.first, "updatedBy") if hv.any?
98
+ save_doc bib, check_duplicate: false
99
+ end
100
+ series = match[:series]
101
+ end
102
+ end
103
+ end
104
+
105
+ #
106
+ # Create unversioned bibliographic item
107
+ #
108
+ # @param [String] ref reference
109
+ # @param [Array<String>] versions list of versions
110
+ #
111
+ def create_series(ref, versions)
112
+ return if versions.size < 2
113
+
114
+ fref = RelatonBib::FormattedRef.new content: ref
115
+ rel = versions.map do |v|
116
+ version_relation v, "includes"
117
+ end
118
+ save_doc IetfBibliographicItem.new(formattedref: fref, relation: rel)
119
+ end
120
+
121
+ #
122
+ # Create bibitem relation
123
+ #
124
+ # @param [String] ref reference
125
+ # @param [String] type relation type
126
+ #
127
+ # @return [RelatonBib::DocumentRelation] relation
128
+ #
129
+ def version_relation(ref, type)
130
+ fref = RelatonBib::FormattedRef.new content: ref
131
+ bibitem = IetfBibliographicItem.new formattedref: fref
132
+ RelatonBib::DocumentRelation.new(type: type, bibitem: bibitem)
133
+ end
134
+
135
+ #
136
+ # Redad saved documents
137
+ #
138
+ # @param [String] file path to file
139
+ #
140
+ # @return [RelatonIetf::IetfBibliographicItem] bibliographic item
141
+ #
142
+ def read_doc(file)
143
+ doc = File.read(file, encoding: "UTF-8")
144
+ case @format
145
+ when "xml" then XMLParser.from_xml(doc)
146
+ when "yaml" then IetfBibliographicItem.from_hash YAML.safe_load(doc)
147
+ else BibXMLParser.parse(doc)
148
+ end
149
+ end
150
+
151
+ #
152
+ # Fetches ietf-rfc-entries documents
153
+ #
72
154
  def fetch_ieft_rfcs
73
155
  rfc_index.xpath("xmlns:rfc-entry").each do |doc|
74
156
  save_doc RfcEntry.parse(doc)
@@ -78,6 +160,11 @@ module RelatonIetf
78
160
  end
79
161
  end
80
162
 
163
+ #
164
+ # Get RFC index
165
+ #
166
+ # @return [Nokogiri::XML::Document] RFC index
167
+ #
81
168
  def rfc_index
82
169
  uri = URI "https://www.rfc-editor.org/rfc-index.xml"
83
170
  Nokogiri::XML(Net::HTTP.get(uri)).at("/xmlns:rfc-index")
@@ -87,8 +174,9 @@ module RelatonIetf
87
174
  # Save document to file
88
175
  #
89
176
  # @param [RelatonIetf::RfcIndexEntry, nil] rfc index entry
177
+ # @param [Boolean] check_duplicate check for duplicate
90
178
  #
91
- def save_doc(entry) # rubocop:disable Metrics/MethodLength
179
+ def save_doc(entry, check_duplicate: true) # rubocop:disable Metrics/MethodLength, Metrics/CyclomaticComplexity
92
180
  return unless entry
93
181
 
94
182
  c = case @format
@@ -97,9 +185,9 @@ module RelatonIetf
97
185
  else entry.send("to_#{@format}")
98
186
  end
99
187
  file = file_name entry
100
- if @files.include? file
188
+ if check_duplicate && @files.include?(file)
101
189
  warn "File #{file} already exists. Document: #{entry.docnumber}"
102
- else
190
+ elsif check_duplicate
103
191
  @files << file
104
192
  end
105
193
  File.write file, c, encoding: "UTF-8"
@@ -112,11 +200,11 @@ module RelatonIetf
112
200
  #
113
201
  # @return [String] file name
114
202
  #
115
- def file_name(entry)
203
+ def file_name(entry) # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
116
204
  id = if entry.respond_to? :docidentifier
117
205
  entry.docidentifier.detect { |i| i.type == "Internet-Draft" }&.id
118
206
  end
119
- id ||= entry.docnumber
207
+ id ||= entry.docnumber || entry.formattedref.content
120
208
  if @source == "ietf-internet-drafts" then id.downcase!
121
209
  else id.upcase!
122
210
  end
@@ -78,9 +78,9 @@ module RelatonIetf
78
78
  end
79
79
 
80
80
  def parse_relation
81
- @is_also.map do |ref|
81
+ @is_also.each_with_object([]) do |ref, a|
82
82
  bib = IetfBibliography.get ref.sub(/^(RFC)(\d+)/, '\1 \2')
83
- { type: "includes", bibitem: bib }
83
+ a << { type: "includes", bibitem: bib } if bib
84
84
  end
85
85
  end
86
86
  end
@@ -1,3 +1,3 @@
1
1
  module RelatonIetf
2
- VERSION = "1.10.5".freeze
2
+ VERSION = "1.10.6".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton-ietf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.10.5
4
+ version: 1.10.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-03-22 00:00:00.000000000 Z
11
+ date: 2022-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: equivalent-xml