relaton 1.19.0 → 1.19.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f0ddaf211c05222758cc04c4183f57c326c45d3a3edb2ae24e1abb6c394db5f
4
- data.tar.gz: 9757e439532532367945ce41b14f5b7941f8e141615c5a8f690422d9f8b77654
3
+ metadata.gz: 7df2abbb732f8ab1fedc92f73e6f313af63075e1cf8f5e0cab2883d7abeaa448
4
+ data.tar.gz: 8915346acdf65d4a129da2b982b07429a5d4c5352874c230adf3189c670d677c
5
5
  SHA512:
6
- metadata.gz: 3ad04fc9310b0d477df6243411f9aa2e5740a47e231eec23d45270d60aecf5633e600fd629d2e315b7b284bc7a3304c0df7370a7418c64181b7ac46565b65c5a
7
- data.tar.gz: 2bd8e7681cb05369277bfc3f84f9741d75fe79a44d311863e2b563010bb94b14c8414903e0941ced1b67448032a5a3d94172c1773f605f58b80b27be421b6d9a
6
+ metadata.gz: 3978d4e5a0e4ab36f49998140d18b9d57e3bce51c943c294fabf04ca16314ebe55cd470fc4de791d9a0c5c274cff0b7fdb889a3d3ca0ebb868cc4a4bcb154d86
7
+ data.tar.gz: 86462982a81ebde5250a3b3c2b95d5f6b9859af635a2a624276af15272f7479a95372de8336d9507ddd150e2af9c684b35de3c85e5ffc29ec4044ffefb79ff5d
data/lib/relaton/db.rb CHANGED
@@ -28,6 +28,7 @@ module Relaton
28
28
  @db&.clear
29
29
  @local_db&.clear
30
30
  @registry.processors.each_value do |p|
31
+ require p.short.to_s
31
32
  p.remove_index_file if p.respond_to? :remove_index_file
32
33
  end
33
34
  end
@@ -59,7 +60,7 @@ module Relaton
59
60
  def fetch(text, year = nil, opts = {})
60
61
  reference = text.strip
61
62
  stdclass = @registry.class_by_ref(reference) || return
62
- processor = @registry.processors[stdclass]
63
+ processor = @registry[stdclass]
63
64
  ref = if processor.respond_to?(:urn_to_code)
64
65
  processor.urn_to_code(reference)&.first
65
66
  else reference
@@ -105,7 +106,7 @@ module Relaton
105
106
  stdclass = @registry.class_by_ref ref
106
107
  if stdclass
107
108
  unless @queues[stdclass]
108
- processor = @registry.processors[stdclass]
109
+ processor = @registry[stdclass]
109
110
  threads = ENV["RELATON_FETCH_PARALLEL"]&.to_i || processor.threads
110
111
  wp = WorkersPool.new(threads) do |args|
111
112
  args[3].call fetch(*args[0..2])
@@ -157,7 +158,7 @@ module Relaton
157
158
  def docid_type(code)
158
159
  stdclass = @registry.class_by_ref(code) or return [nil, code]
159
160
  _, code = strip_id_wrapper(code, stdclass)
160
- [@registry.processors[stdclass].idtype, code]
161
+ [@registry[stdclass].idtype, code]
161
162
  end
162
163
 
163
164
  # @param key [String]
@@ -293,7 +294,7 @@ module Relaton
293
294
  else return
294
295
  end
295
296
 
296
- doc = @registry.processors[stdclass].hash_to_bib docid: { id: code }
297
+ doc = @registry[stdclass].hash_to_bib docid: { id: code }
297
298
  ref = refs[0]
298
299
  updates = check_bibliocache(refs[0], year, opts, stdclass)
299
300
  if updates
@@ -336,7 +337,7 @@ module Relaton
336
337
  # @param stdClass [Symbol]
337
338
  # @return [Array]
338
339
  def strip_id_wrapper(code, stdclass)
339
- prefix = @registry.processors[stdclass].prefix
340
+ prefix = @registry[stdclass].prefix
340
341
  code = code.sub(/\u2013/, "-").sub(/^#{prefix}\((.+)\)$/, "\\1")
341
342
  [prefix, code]
342
343
  end
@@ -355,7 +356,7 @@ module Relaton
355
356
  # RelatonOmg::OmgBibliographicItem, RelatonW3c::W3cBibliographicItem]
356
357
  def bib_retval(entry, stdclass)
357
358
  if entry && !entry.match?(/^not_found/)
358
- @registry.processors[stdclass].from_xml(entry)
359
+ @registry[stdclass].from_xml(entry)
359
360
  end
360
361
  end
361
362
 
@@ -443,7 +444,7 @@ module Relaton
443
444
  end
444
445
 
445
446
  def fetch_entry(code, year, opts, stdclass, **args)
446
- processor = @registry.processors[stdclass]
447
+ processor = @registry[stdclass]
447
448
  bib = net_retry(code, year, opts, processor, opts.fetch(:retries, 1))
448
449
 
449
450
  entry = check_entry(bib, stdclass, **args)
@@ -10,7 +10,7 @@ module Relaton
10
10
  relaton_ogc relaton_calconnect relaton_omg relaton_un relaton_w3c
11
11
  relaton_ieee relaton_iho relaton_bipm relaton_ecma relaton_cie relaton_bsi
12
12
  relaton_cen relaton_iana relaton_3gpp relaton_oasis relaton_doi relaton_jis
13
- relaton_xsf relaton_ccsds relaton_etsi relaton_isbn
13
+ relaton_xsf relaton_ccsds relaton_etsi relaton_isbn relaton/plateau
14
14
  ].freeze
15
15
 
16
16
  include Singleton
@@ -26,7 +26,6 @@ module Relaton
26
26
  # Util.info("Info: detecting backends:")
27
27
 
28
28
  SUPPORTED_GEMS.each do |b|
29
- require b
30
29
  require "#{b}/processor"
31
30
  register Kernel.const_get "#{camel_case(b)}::Processor"
32
31
  rescue LoadError => e
@@ -61,7 +60,7 @@ module Relaton
61
60
  # @return [Relaton::Processor, nil]
62
61
  #
63
62
  def find_processor_by_dataset(dataset)
64
- processors.values.detect { |p| p.datasets&.include? dataset }
63
+ require_gem(processors.values.detect { |p| p.datasets&.include? dataset })
65
64
  end
66
65
 
67
66
  #
@@ -73,7 +72,18 @@ module Relaton
73
72
  # RelatonGb::Processor, RelatonOgc::Processor,
74
73
  # RelatonCalconnect::Processor]
75
74
  def by_type(type)
76
- processors.values.detect { |v| v.prefix == type&.upcase }
75
+ require_gem(processors.values.detect { |v| v.prefix == type&.upcase })
76
+ end
77
+
78
+ def [](stdclass)
79
+ require_gem processors[stdclass]
80
+ end
81
+
82
+ def require_gem(processor)
83
+ return unless processor
84
+
85
+ require processor.short.to_s
86
+ processor
77
87
  end
78
88
 
79
89
  #
@@ -84,7 +94,7 @@ module Relaton
84
94
  # @return [Relaton::Processor] processor
85
95
  #
86
96
  def processor_by_ref(ref)
87
- @processors[class_by_ref(ref)]
97
+ require_gem processors[class_by_ref(ref)]
88
98
  end
89
99
 
90
100
  #
@@ -95,7 +105,7 @@ module Relaton
95
105
  # @return [Symbol, nil] standard class name
96
106
  #
97
107
  def class_by_ref(ref)
98
- ref = ref.match(/^\w+\((.*)\)$/) ? Regexp.last_match(1) : ref
108
+ ref = ref =~ /^\w+\((.*)\)$/ ? Regexp.last_match(1) : ref
99
109
  @processors.each do |class_name, processor|
100
110
  return class_name if /^(urn:)?#{processor.prefix}\b/i.match?(ref) ||
101
111
  processor.defaultprefix.match(ref)
@@ -107,7 +117,9 @@ module Relaton
107
117
  private
108
118
 
109
119
  def camel_case(gem_name)
110
- gem_name.split("_").map(&:capitalize).join
120
+ gem_name.split("/").map do |part|
121
+ part.split("_").map(&:capitalize).join
122
+ end.join("::")
111
123
  end
112
124
  end
113
125
  end
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "1.19.0".freeze
2
+ VERSION = "1.19.2".freeze
3
3
  end
data/relaton.gemspec CHANGED
@@ -53,6 +53,7 @@ Gem::Specification.new do |spec|
53
53
  spec.add_dependency "relaton-oasis", "~> 1.19.0"
54
54
  spec.add_dependency "relaton-ogc", "~> 1.19.0"
55
55
  spec.add_dependency "relaton-omg", "~> 1.19.0"
56
+ spec.add_dependency "relaton-plateau", "~> 1.19.0"
56
57
  spec.add_dependency "relaton-un", "~> 1.19.0"
57
58
  spec.add_dependency "relaton-w3c", "~> 1.19.0"
58
59
  spec.add_dependency "relaton-xsf", "~> 1.19.0"
@@ -17,7 +17,7 @@ RSpec.describe Relaton::Processor do
17
17
  end
18
18
 
19
19
  it "fetch_data method should be implemented" do
20
- expect { subject.fetch_data "cource", {} }.to raise_error StandardError
20
+ expect { subject.fetch_data "source", {} }.to raise_error StandardError
21
21
  end
22
22
 
23
23
  it "from_xml method should be implemented" do
@@ -43,7 +43,7 @@ RSpec.describe Relaton::Processor do
43
43
 
44
44
  it "get method should call get method of #{flavor}" do
45
45
  expect(bibliography).to receive(:get).with("code", nil, {}).and_return :item
46
- expect(processor.get "code", nil, {}).to eq :item
46
+ expect(processor.get("code", nil, {})).to eq :item
47
47
  end
48
48
 
49
49
  it "grammar_hash method should call grammar_hash method of #{flavor}" do
@@ -58,7 +58,7 @@ RSpec.describe Relaton::Processor do
58
58
 
59
59
  it "fetch_data method should call fetch_data method of #{flavor}" do
60
60
  expect(fetcher_class).to receive(:fetch).with(output: "dir", format: "bibxml").and_return :item
61
- expect(processor.fetch_data source, output: "dir", format: "bibxml").to eq :item
61
+ expect(processor.fetch_data(source, output: "dir", format: "bibxml")).to eq :item
62
62
  end
63
63
  end
64
64
 
@@ -68,7 +68,7 @@ RSpec.describe Relaton::Processor do
68
68
 
69
69
  it "from_xml method should call from_xml method of #{flavor}" do
70
70
  expect(parser_class).to receive(:from_xml).with("xml").and_return :item
71
- expect(processor.from_xml "xml").to eq :item
71
+ expect(processor.from_xml("xml")).to eq :item
72
72
  end
73
73
  end
74
74
 
@@ -127,6 +127,42 @@ RSpec.describe Relaton::Registry do
127
127
  it "ISBN" do
128
128
  expect(Relaton::Registry.instance.by_type("ISBN")).to be_instance_of RelatonIsbn::Processor
129
129
  end
130
+
131
+ context "PLATEAU" do
132
+ let(:processor) { Relaton::Registry.instance.by_type("PLATEAU") }
133
+ before { processor }
134
+
135
+ it "finds processor" do
136
+ expect(processor).to be_instance_of Relaton::Plateau::Processor
137
+ end
138
+
139
+ it "fetch data" do
140
+ expect(Relaton::Plateau::Fetcher).to receive(:fetch).with("plateau-handbooks", output: "dir", format: "xml")
141
+ processor.fetch_data "plateau-handbooks", output: "dir", format: "xml"
142
+ end
143
+
144
+ it "from_xml" do
145
+ expect(Relaton::Plateau::XMLParser).to receive(:from_xml).with(:xml).and_return :bibitem
146
+ expect(processor.from_xml(:xml)).to eq :bibitem
147
+ end
148
+
149
+ it "hash_to_bib" do
150
+ expect(Relaton::Plateau::HashConverter).to receive(:hash_to_bib).with(:hash).and_return bib: :bib
151
+ expect(Relaton::Plateau::BibItem).to receive(:new).with(bib: :bib).and_return :bibitem
152
+ expect(processor.hash_to_bib(:hash)).to eq :bibitem
153
+ end
154
+
155
+ it "grammar_hash" do
156
+ expect(processor.grammar_hash).to be_instance_of String
157
+ end
158
+
159
+ it "remove_index_file" do
160
+ index = double "index"
161
+ expect(index).to receive(:remove_file)
162
+ expect(Relaton::Index).to receive(:find_or_create).and_return index
163
+ processor.remove_index_file
164
+ end
165
+ end
130
166
  end
131
167
 
132
168
  it "find processot by dataset" do
data/spec/relaton_spec.rb CHANGED
@@ -373,6 +373,15 @@ RSpec.describe Relaton::Db do
373
373
  expect(bib.docidentifier.first.id).to eq "ISBN 978-0-580-50101-4"
374
374
  end
375
375
 
376
+ it "get PLATEAU reference" do
377
+ docid = RelatonBib::DocumentIdentifier.new(id: "PLATEAU Hanbook #01", type: "PLATEAU")
378
+ item = Relaton::Plateau::BibItem.new docid: [docid]
379
+ expect(Relaton::Plateau::Bibliography).to receive(:get).with("PLATEAU Hanbook #01", nil, {}).and_return item
380
+ bib = @db.fetch "PLATEAU Hanbook #01"
381
+ expect(bib).to be_instance_of Relaton::Plateau::BibItem
382
+ expect(bib.docidentifier.first.id).to eq "PLATEAU Hanbook #01"
383
+ end
384
+
376
385
  context "get combined documents" do
377
386
  context "ISO" do
378
387
  it "included" do
@@ -481,7 +490,7 @@ RSpec.describe Relaton::Db do
481
490
  it "should clear cache if version is changed" do
482
491
  expect(File.read("testcache/iso/version", encoding: "UTF-8")).not_to eq "new_version"
483
492
  expect(File.read("testcache2/iso/version", encoding: "UTF-8")).not_to eq "new_version"
484
- processor = double
493
+ processor = double "processor", short: :relaton_iso
485
494
  expect(processor).to receive(:grammar_hash).and_return("new_version").exactly(2).times
486
495
  expect(Relaton::Registry.instance).to receive(:by_type).and_return(processor).exactly(2).times
487
496
  Relaton::Db.new "testcache", "testcache2"