relaton 1.7.6 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/docs/README.adoc +20 -11
  3. data/lib/relaton/config.rb +4 -2
  4. data/lib/relaton/db.rb +127 -81
  5. data/lib/relaton/db_cache.rb +6 -0
  6. data/lib/relaton/registry.rb +3 -2
  7. data/lib/relaton/util.rb +3 -1
  8. data/lib/relaton/version.rb +1 -1
  9. data/lib/relaton/workers_pool.rb +1 -3
  10. data/relaton.gemspec +19 -17
  11. data/spec/relaton/config_spec.rb +1 -1
  12. data/spec/relaton/db_spec.rb +48 -16
  13. data/spec/relaton/regirtry_spec.rb +9 -1
  14. data/spec/relaton_spec.rb +23 -9
  15. data/spec/vcr_cassetes/19133_2005.yml +22 -22
  16. data/spec/vcr_cassetes/async_fetch.yml +4742 -0
  17. data/spec/vcr_cassetes/bsi_bs_en_iso_8848.yml +159 -0
  18. data/spec/vcr_cassetes/cc_dir_10005_2019.yml +12 -12
  19. data/spec/vcr_cassetes/cen_en_10160_1999.yml +249 -0
  20. data/spec/vcr_cassetes/cie_001_1980.yml +7 -7
  21. data/spec/vcr_cassetes/ecma_6.yml +7 -7
  22. data/spec/vcr_cassetes/fisp_140.yml +4 -4
  23. data/spec/vcr_cassetes/gb_t_20223_2006.yml +9 -9
  24. data/spec/vcr_cassetes/iec_60050_102_2007.yml +35 -33
  25. data/spec/vcr_cassetes/iec_combined_included.yml +98 -164
  26. data/spec/vcr_cassetes/ieee_528_2019.yml +41 -39
  27. data/spec/vcr_cassetes/iho_b_11.yml +7 -7
  28. data/spec/vcr_cassetes/iso_111111119115_1.yml +4 -4
  29. data/spec/vcr_cassetes/iso_19115.yml +21 -21
  30. data/spec/vcr_cassetes/iso_19115_1.yml +22 -22
  31. data/spec/vcr_cassetes/iso_19115_1_2.yml +43 -43
  32. data/spec/vcr_cassetes/iso_awi_14093.yml +182 -0
  33. data/spec/vcr_cassetes/iso_combined_applied.yml +42 -42
  34. data/spec/vcr_cassetes/iso_combined_included.yml +45 -45
  35. data/spec/vcr_cassetes/itu_combined_included.yml +813 -681
  36. data/spec/vcr_cassetes/ogc_19_025r1.yml +1307 -1158
  37. data/spec/vcr_cassetes/omg_ami4ccm_1_0.yml +43 -0
  38. data/spec/vcr_cassetes/rfc_8341.yml +7 -7
  39. data/spec/vcr_cassetes/sp_800_38b.yml +4 -4
  40. data/spec/vcr_cassetes/un_rtade_cefact_2004_32.yml +34 -34
  41. data/spec/vcr_cassetes/w3c_json_ld11.yml +17 -17
  42. metadata +69 -40
  43. data/localcache/iec/iec_60050_102_2007.xml +0 -58
  44. data/localcache/iec/version +0 -1
  45. data/spec/vcr_cassetes/iso_awi_24229.yml +0 -182
  46. data/spec/vcr_cassetes/ogm_ami4ccm_1_0.yml +0 -55
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fdf3d2a7e0d55bf5b5edf65ef0e6f1f3d3ce5648388b6bae43127040df90d881
4
- data.tar.gz: d3cc65b7002c57f6e72c86dccfab92956a992fcfef9ce836ec5b3b4806646e88
3
+ metadata.gz: 910d5cfba1e4dfc56255a635d7d3c2169b2e3597b519c2f680a1a0be35686551
4
+ data.tar.gz: 8f3950346e378dca736504e3b90f82949f75dc678b7fc63f1b8cfd9de9c42339
5
5
  SHA512:
6
- metadata.gz: ae4cba856c12417b10308310c14aec5e2d4452c0c24a4fe30b597d57b7c142e138e858fb97ad452bb29488e3d5d4b0a6bc1fde8dcc41bd4bb10c837315dc7257
7
- data.tar.gz: e47b6c8e2feb25956d77df52352a474936168854263aeb354d526890b63428d420eeebdc7be6f6547689ec5a25e5a1b2045c72d82680ae7e234c5d1d42023579
6
+ metadata.gz: ad94b90beaaffd6df9a0635e8b25df571187235dea448386f6d2e2829582ace5902aa1f379211687124d95b805f31854dbcc0a0c19927eb2bf0050bbaf9e75c9
7
+ data.tar.gz: fa687c31ab34f8843b84463a55f042b957f1394b6e8b5675d92719fcd3e7fe010a8f2bd0c44348fd387314cdf0bc6792e3d153552fec9b713fb5996550d99563
data/docs/README.adoc CHANGED
@@ -106,14 +106,18 @@ db = Relaton::Db.new("globalcache", "localcache")
106
106
 
107
107
  ==== Move DB
108
108
 
109
- `Relaton::Db#mv(new_globalcache_dir, new_localcahe_dir)` moves DB directories to new location.
109
+ `Relaton::Db#mv(new_dir, type: :global)` moves DB directory to new location. Returns path to new directory if successful, or `nil` if target directiory exists.
110
110
 
111
- * `new_globalcahe_dir` - (String or nil) new globalcache location
112
- * `new_localcahe_dir` - (String or nil) new localcache location
111
+ * `new_dir` - (String) new cache location
112
+ * `type` - (Symbol) type of cache DB. Allowed values are: `:global`, `:local`. Default is `:global`.
113
113
 
114
114
  [source,ruby]
115
115
  ----
116
- db.mv("new_globalcache_dir", "new_localcahe_dir")
116
+ db.mv("new_global_dir")
117
+ => "new_global_dir"
118
+
119
+ db.mv("new_local_dir", type: :local)
120
+ => "new_local_dir"
117
121
  ----
118
122
 
119
123
  ==== Clear DB
@@ -178,14 +182,19 @@ x = db.fetch_db("ISO 5749")
178
182
  # prepare queue for results
179
183
  results = Queue.new
180
184
 
181
- # fetch document
182
- db.fetch_async("ISO 19115") do |result|
183
- results << { "ISO 19115" => result }
185
+ # references ot fetch
186
+ refs = ["ISO 19011", "ISO 19115"]
187
+
188
+ # fetch documents
189
+ refs.each do |ref|
190
+ db.fetch_async(ref) do |doc|
191
+ results << [ref, doc]
192
+ end
184
193
  end
185
- # fetch other documets the same way
186
194
 
187
195
  # wait until documets fetching
188
- while x = results.pop
196
+ refs.size.times do
197
+ ref, doc = results.pop
189
198
  # do thatever you need with result x
190
199
  end
191
200
  ----
@@ -330,7 +339,7 @@ ISO/IEC DIR 1
330
339
  ISO/IEC DIR 2 IEC
331
340
  ISO/IEC DIR 2 ISO
332
341
  ISO/IEC DIR IEC SUP
333
- ISO/IEC DIR 1 ISO SUP
342
+ ISO/IEC DIR 1 JTC SUP
334
343
  ----
335
344
 
336
345
  === Get document type
@@ -368,7 +377,7 @@ x.to_xml bibdata: true
368
377
  db.load_entry("ISO(ISO 19011)")
369
378
  => "<bibdata type="standard">
370
379
  ...
371
- <?bibdata>"
380
+ </bibdata>"
372
381
  ----
373
382
 
374
383
  === Entry manipulation
@@ -15,8 +15,10 @@ module Relaton
15
15
  attr_accessor :logs, :use_api
16
16
 
17
17
  def initialize
18
- @logs = %i(warning error)
19
- @use_api = false # @TODO change to true when we start using api.relaton.org
18
+ @logs = %i(info error) # allowed values: :info, :warning, :error, :debug
19
+
20
+ # @TODO change to true when we start using api.relaton.org
21
+ @use_api = false
20
22
  end
21
23
  end
22
24
 
data/lib/relaton/db.rb CHANGED
@@ -10,51 +10,64 @@ module Relaton
10
10
  # @param local_cache [String] directory of local DB
11
11
  def initialize(global_cache, local_cache)
12
12
  @registry = Relaton::Registry.instance
13
- @db = open_cache_biblio(global_cache, type: :global)
14
- @local_db = open_cache_biblio(local_cache, type: :local)
15
- @static_db = open_cache_biblio File.expand_path("../relaton/static_cache", __dir__)
13
+ gpath = global_cache && File.expand_path(global_cache)
14
+ @db = open_cache_biblio(gpath, type: :global)
15
+ lpath = local_cache && File.expand_path(local_cache)
16
+ @local_db = open_cache_biblio(lpath, type: :local)
17
+ @static_db = open_cache_biblio File.expand_path("../relaton/static_cache",
18
+ __dir__)
16
19
  @queues = {}
17
20
  end
18
21
 
19
- # Move global and/or local caches to anothe dirs
20
- # @param new_global_dir [String, nil]
21
- # @param new_local_dir [String, nil]
22
- def mv(new_global_dir, new_local_dir)
23
- @db.mv new_global_dir
24
- @local_db.mv new_local_dir
22
+ # Move global or local caches to anothe dirs
23
+ # @param new_dir [String, nil]
24
+ # @param type: [Symbol]
25
+ # @return [String, nil]
26
+ def mv(new_dir, type: :global)
27
+ case type
28
+ when :global
29
+ @db&.mv new_dir
30
+ when :local
31
+ @local_db&.mv new_dir
32
+ end
25
33
  end
26
34
 
27
35
  # Clear global and local databases
28
36
  def clear
29
- @db.clear
30
- @local_db.clear
37
+ @db&.clear
38
+ @local_db&.clear
31
39
  end
32
40
 
33
41
  ##
34
42
  # The class of reference requested is determined by the prefix of the code:
35
- # GB Standard for gbbib, IETF for ietfbib, ISO for isobib, IEC or IEV for iecbib,
43
+ # GB Standard for gbbib, IETF for ietfbib, ISO for isobib, IEC or IEV for
44
+ # iecbib,
36
45
  #
37
46
  # @param code [String] the ISO standard Code to look up (e.g. "ISO 9000")
38
47
  # @param year [String] the year the standard was published (optional)
39
48
  #
40
49
  # @param opts [Hash] options
41
50
  # @option opts [Boolean] :all_parts If all-parts reference is required
42
- # @option opts [Boolean] :keep_year If undated reference should return actual reference with year
51
+ # @option opts [Boolean] :keep_year If undated reference should return
52
+ # actual reference with year
43
53
  # @option opts [Integer] :retries (1) Number of network retries
44
54
  #
45
- # @return [nil, RelatonBib::BibliographicItem, RelatonIsoBib::IsoBibliographicItem,
46
- # RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
47
- # RelatonIec::IecBibliographicItem, RelatonIeee::IeeeBibliographicItem,
48
- # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem,
49
- # RelatonOgc::OgcBibliographicItem, RelatonCalconnect::CcBibliographicItem]
55
+ # @return [nil, RelatonBib::BibliographicItem,
56
+ # RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
57
+ # RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
58
+ # RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
59
+ # RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
60
+ # RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
50
61
  # RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
51
- # RelatonOmg::OmgBibliographicItem RelatinUn::UnBibliographicItem,
52
- # RelatonW3c::W3cBibliographicItem
62
+ # RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
53
63
  ##
54
64
  def fetch(code, year = nil, opts = {})
55
65
  stdclass = standard_class(code) || return
56
66
  processor = @registry.processors[stdclass]
57
- ref = processor.respond_to?(:urn_to_code) ? processor.urn_to_code(code)&.first : code
67
+ ref = if processor.respond_to?(:urn_to_code)
68
+ processor.urn_to_code(code)&.first
69
+ else code
70
+ end
58
71
  ref ||= code
59
72
  result = combine_doc ref, year, opts, stdclass
60
73
  result ||= check_bibliocache(ref, year, opts, stdclass)
@@ -73,9 +86,15 @@ module Relaton
73
86
  # @param year [Integer, nil]
74
87
  # @return [Array]
75
88
  def fetch_all(text = nil, edition: nil, year: nil)
76
- result = @static_db.all { |file, yml| search_yml file, yml, text, edition, year }.compact
89
+ result = @static_db.all do |file, yml|
90
+ search_yml file, yml, text, edition, year
91
+ end.compact
77
92
  db = @db || @local_db
78
- result += db.all { |file, xml| search_xml file, xml, text, edition, year }.compact if db
93
+ if db
94
+ result += db.all do |file, xml|
95
+ search_xml file, xml, text, edition, year
96
+ end.compact
97
+ end
79
98
  result
80
99
  end
81
100
 
@@ -100,17 +119,18 @@ module Relaton
100
119
  #
101
120
  # @param opts [Hash]
102
121
  # @option opts [Boolean] :all_parts If all-parts reference is required
103
- # @option opts [Boolean] :keep_year If undated reference should return actual reference with year
122
+ # @option opts [Boolean] :keep_year If undated reference should return
123
+ # actual reference with year
104
124
  # @option opts [Integer] :retries (1) Number of network retries
105
125
  #
106
- # @return [nil, RelatonBib::BibliographicItem, RelatonIsoBib::IsoBibliographicItem,
107
- # RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
108
- # RelatonIec::IecBibliographicItem, RelatonIeee::IeeeBibliographicItem,
109
- # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem,
110
- # RelatonOgc::OgcBibliographicItem, RelatonCalconnect::CcBibliographicItem]
126
+ # @return [nil, RelatonBib::BibliographicItem,
127
+ # RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
128
+ # RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
129
+ # RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
130
+ # RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
131
+ # RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
111
132
  # RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
112
- # RelatonOmg::OmgBibliographicItem RelatinUn::UnBibliographicItem,
113
- # RelatonW3c::W3cBibliographicItem
133
+ # RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
114
134
  def fetch_std(code, year = nil, stdclass = nil, opts = {})
115
135
  std = nil
116
136
  @registry.processors.each do |name, processor|
@@ -193,9 +213,11 @@ module Relaton
193
213
  # @return [BibliographicItem, nil]
194
214
  def search_edition_year(file, content, edition, year) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
195
215
  processor = @registry.processors[standard_class(file.split("/")[-2])]
196
- item = file.match?(/xml$/) ? processor.from_xml(content) : processor.hash_to_bib(YAML.safe_load(content))
197
- item if (edition.nil? || item.edition == edition) &&
198
- (year.nil? || item.date.detect { |d| d.type == "published" && d.on(:year) == year })
216
+ item = if file.match?(/xml$/) then processor.from_xml(content)
217
+ else processor.hash_to_bib(YAML.safe_load(content))
218
+ end
219
+ item if (edition.nil? || item.edition == edition) && (year.nil? ||
220
+ item.date.detect { |d| d.type == "published" && d.on(:year).to_s == year.to_s })
199
221
  end
200
222
 
201
223
  # @param xml [String] content in XML format
@@ -211,18 +233,19 @@ module Relaton
211
233
  #
212
234
  # @param opts [Hash] options
213
235
  # @option opts [Boolean] :all_parts If all-parts reference is required
214
- # @option opts [Boolean] :keep_year If undated reference should return actual reference with year
236
+ # @option opts [Boolean] :keep_year If undated reference should return
237
+ # actual reference with year
215
238
  # @option opts [Integer] :retries (1) Number of network retries
216
239
  #
217
- # @return [nil, RelatonBib::BibliographicItem, RelatonIsoBib::IsoBibliographicItem,
218
- # RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
219
- # RelatonIec::IecBibliographicItem, RelatonIeee::IeeeBibliographicItem,
220
- # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem,
221
- # RelatonOgc::OgcBibliographicItem, RelatonCalconnect::CcBibliographicItem]
240
+ # @return [nil, RelatonBib::BibliographicItem,
241
+ # RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
242
+ # RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
243
+ # RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
244
+ # RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
245
+ # RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
222
246
  # RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
223
- # RelatonOmg::OmgBibliographicItem RelatinUn::UnBibliographicItem,
224
- # RelatonW3c::W3cBibliographicItem
225
- def combine_doc(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
247
+ # RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
248
+ def combine_doc(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/MethodLength,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
226
249
  if (refs = code.split " + ").size > 1
227
250
  reltype = "derivedFrom"
228
251
  reldesc = nil
@@ -235,11 +258,17 @@ module Relaton
235
258
  doc = @registry.processors[stdclass].hash_to_bib docid: { id: code }
236
259
  ref = refs[0]
237
260
  updates = check_bibliocache(ref, year, opts, stdclass)
238
- doc.relation << RelatonBib::DocumentRelation.new(bibitem: updates, type: "updates") if updates
261
+ if updates
262
+ doc.relation << RelatonBib::DocumentRelation.new(bibitem: updates,
263
+ type: "updates")
264
+ end
265
+ divider = stdclass == :relaton_itu ? " " : "/"
239
266
  refs[1..-1].each_with_object(doc) do |c, d|
240
- bib = check_bibliocache("#{ref}/#{c}", year, opts, stdclass)
267
+ bib = check_bibliocache(ref + divider + c, year, opts, stdclass)
241
268
  if bib
242
- d.relation << RelatonBib::DocumentRelation.new(type: reltype, description: reldesc, bibitem: bib)
269
+ d.relation << RelatonBib::DocumentRelation.new(
270
+ type: reltype, description: reldesc, bibitem: bib
271
+ )
243
272
  end
244
273
  end
245
274
  end
@@ -254,8 +283,8 @@ module Relaton
254
283
  allowed = @registry.processors.reduce([]) do |m, (_k, v)|
255
284
  m << v.prefix
256
285
  end
257
- warn <<~WARN
258
- #{code} does not have a recognised prefix: #{allowed.join(', ')}.
286
+ Util.log <<~WARN, :info
287
+ [relaton] #{code} does not have a recognised prefix: #{allowed.join(', ')}.
259
288
  See https://github.com/relaton/relaton/ for instructions on prefixing and wrapping document identifiers to disambiguate them.
260
289
  WARN
261
290
  end
@@ -267,7 +296,8 @@ module Relaton
267
296
  #
268
297
  # @param opts [Hash]
269
298
  # @option opts [Boolean] :all_parts If all-parts reference is required
270
- # @option opts [Boolean] :keep_year If undated reference should return actual reference with year
299
+ # @option opts [Boolean] :keep_year If undated reference should return
300
+ # actual reference with year
271
301
  # @option opts [Integer] :retries (1) Number of network retries
272
302
  #
273
303
  # @param stdClass [Symbol]
@@ -292,16 +322,18 @@ module Relaton
292
322
 
293
323
  # @param entry [String] XML string
294
324
  # @param stdclass [Symbol]
295
- # @return [nil, RelatonBib::BibliographicItem, RelatonIsoBib::IsoBibliographicItem,
296
- # RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
297
- # RelatonIec::IecBibliographicItem, RelatonIeee::IeeeBibliographicItem,
298
- # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem,
299
- # RelatonOgc::OgcBibliographicItem, RelatonCalconnect::CcBibliographicItem]
325
+ # @return [nil, RelatonBib::BibliographicItem,
326
+ # RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
327
+ # RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
328
+ # RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
329
+ # RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
330
+ # RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
300
331
  # RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
301
- # RelatonOmg::OmgBibliographicItem RelatinUn::UnBibliographicItem,
302
- # RelatonW3c::W3cBibliographicItem
332
+ # RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
303
333
  def bib_retval(entry, stdclass)
304
- entry.nil? || entry.match?(/^not_found/) ? nil : @registry.processors[stdclass].from_xml(entry)
334
+ if entry.nil? || entry.match?(/^not_found/) then nil
335
+ else @registry.processors[stdclass].from_xml(entry)
336
+ end
305
337
  end
306
338
 
307
339
  # @param code [String]
@@ -309,29 +341,33 @@ module Relaton
309
341
  #
310
342
  # @param opts [Hash]
311
343
  # @option opts [Boolean] :all_parts If all-parts reference is required
312
- # @option opts [Boolean] :keep_year If undated reference should return actual reference with year
344
+ # @option opts [Boolean] :keep_year If undated reference should return
345
+ # actual reference with year
313
346
  # @option opts [Integer] :retries (1) Number of network retries
314
347
  #
315
348
  # @param stdclass [Symbol]
316
- # @return [nil, RelatonBib::BibliographicItem, RelatonIsoBib::IsoBibliographicItem,
317
- # RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
318
- # RelatonIec::IecBibliographicItem, RelatonIeee::IeeeBibliographicItem,
319
- # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem,
320
- # RelatonOgc::OgcBibliographicItem, RelatonCalconnect::CcBibliographicItem]
349
+ # @return [nil, RelatonBib::BibliographicItem,
350
+ # RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
351
+ # RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
352
+ # RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
353
+ # RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
354
+ # RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
321
355
  # RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
322
- # RelatonOmg::OmgBibliographicItem RelatinUn::UnBibliographicItem,
323
- # RelatonW3c::W3cBibliographicItem
356
+ # RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
324
357
  def check_bibliocache(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
325
358
  id, searchcode = std_id(code, year, opts, stdclass)
326
359
  yaml = @static_db[id]
327
- return @registry.processors[stdclass].hash_to_bib YAML.safe_load(yaml) if yaml
360
+ if yaml
361
+ return @registry.processors[stdclass].hash_to_bib YAML.safe_load(yaml)
362
+ end
328
363
 
329
364
  db = @local_db || @db
330
365
  altdb = @local_db && @db ? @db : nil
331
366
  if db.nil?
332
367
  return if opts[:fetch_db]
333
368
 
334
- bibentry = new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id)
369
+ bibentry = new_bib_entry(searchcode, year, opts, stdclass, db: db,
370
+ id: id)
335
371
  return bib_retval(bibentry, stdclass)
336
372
  end
337
373
 
@@ -340,12 +376,14 @@ module Relaton
340
376
  return bib_retval(altdb[id], stdclass) if opts[:fetch_db]
341
377
 
342
378
  db.clone_entry id, altdb if altdb.valid_entry? id, year
343
- db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id)
379
+ db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db: db,
380
+ id: id)
344
381
  altdb.clone_entry(id, db) if !altdb.valid_entry?(id, year)
345
382
  else
346
383
  return bib_retval(db[id], stdclass) if opts[:fetch_db]
347
384
 
348
- db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id)
385
+ db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db: db,
386
+ id: id)
349
387
  end
350
388
  bib_retval(db[id], stdclass)
351
389
  end
@@ -355,7 +393,8 @@ module Relaton
355
393
  #
356
394
  # @param opts [Hash]
357
395
  # @option opts [Boolean] :all_parts If all-parts reference is required
358
- # @option opts [Boolean] :keep_year If undated reference should return actual reference with year
396
+ # @option opts [Boolean] :keep_year If undated reference should return
397
+ # actual reference with year
359
398
  # @option opts [Integer] :retries (1) Number of network retries
360
399
  #
361
400
  # @param stdclass [Symbol]
@@ -367,7 +406,8 @@ module Relaton
367
406
  bib_id = bib&.docidentifier&.first&.id
368
407
 
369
408
  # when docid doesn't match bib's id then return a reference to bib's id
370
- if args[:db] && args[:id] && bib_id && args[:id] !~ %r{#{Regexp.quote("(#{bib_id})")}}
409
+ if args[:db] && args[:id] &&
410
+ bib_id && args[:id] !~ %r{#{Regexp.quote("(#{bib_id})")}}
371
411
  bid = std_id(bib.docidentifier.first.id, nil, {}, stdclass).first
372
412
  args[:db][bid] ||= bib_entry bib
373
413
  "redirection #{bid}"
@@ -384,9 +424,14 @@ module Relaton
384
424
  net_retry(code, year, opts, stdclass, retries - 1)
385
425
  end
386
426
 
387
- # @param bib [RelatonGb::GbBibliongraphicItem, RelatonIsoBib::IsoBibliographicItem,
388
- # RelatonIetf::IetfBibliographicItem, RelatonItu::ItuBibliographicItem,
389
- # RelatonNist::NistBibliongraphicItem, RelatonOgc::OgcBibliographicItem]
427
+ # @param bib [RelatonBib::BibliographicItem,
428
+ # RelatonIsoBib::IsoBibliographicItem, RelatonItu::ItuBibliographicItem,
429
+ # RelatonIetf::IetfBibliographicItem, RelatonIec::IecBibliographicItem,
430
+ # RelatonIeee::IeeeBibliographicItem, RelatonNist::NistBibliongraphicItem,
431
+ # RelatonGb::GbbibliographicItem, RelatonOgc::OgcBibliographicItem,
432
+ # RelatonCalconnect::CcBibliographicItem, RelatinUn::UnBibliographicItem,
433
+ # RelatonBipm::BipmBibliographicItem, RelatonIho::IhoBibliographicItem,
434
+ # RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
390
435
  # @return [String] XML or "not_found mm-dd-yyyy"
391
436
  def bib_entry(bib)
392
437
  if bib.respond_to? :to_xml
@@ -399,7 +444,7 @@ module Relaton
399
444
  # @param dir [String, nil] DB directory
400
445
  # @param type [Symbol]
401
446
  # @return [Relaton::DbCache, NilClass]
402
- def open_cache_biblio(dir, type: :static)
447
+ def open_cache_biblio(dir, type: :static) # rubocop:disable Metrics/MethodLength
403
448
  return nil if dir.nil?
404
449
 
405
450
  db = DbCache.new dir, type == :static ? "yml" : "xml"
@@ -408,9 +453,12 @@ module Relaton
408
453
  Dir["#{dir}/*/"].each do |fdir|
409
454
  next if db.check_version?(fdir)
410
455
 
411
- FileUtils.rm_rf(Dir.glob(fdir + "/*"), secure: true)
412
- db.set_version fdir
413
- warn "[relaton] cache #{fdir}: version is obsolete and cache is cleared."
456
+ FileUtils.rm_rf(fdir, secure: true)
457
+ Util.log(
458
+ "[relaton] WARNING: cache #{fdir}: version is obsolete and cache is "\
459
+ "cleared.",
460
+ :warning
461
+ )
414
462
  end
415
463
  db
416
464
  end
@@ -419,9 +467,7 @@ module Relaton
419
467
  # @option qwp [Queue] :queue The queue of references to fetch
420
468
  # @option qwp [Relaton::WorkersPool] :workers_pool The pool of workers
421
469
  def process_queue(qwp)
422
- while args = qwp[:queue].pop
423
- qwp[:workers_pool] << args
424
- end
470
+ while args = qwp[:queue].pop; qwp[:workers_pool] << args end
425
471
  end
426
472
  end
427
473
  end