relaton 1.5.0 → 1.7.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/macos.yml +2 -0
- data/docs/README.adoc +73 -1
- data/lib/relaton/config.rb +1 -1
- data/lib/relaton/db.rb +34 -10
- data/lib/relaton/db_cache.rb +14 -5
- data/lib/relaton/registry.rb +5 -4
- data/lib/relaton/version.rb +1 -1
- data/relaton.gemspec +15 -14
- data/spec/relaton/db_cache_spec.rb +26 -1
- data/spec/relaton/regirtry_spec.rb +7 -3
- data/spec/relaton_spec.rb +142 -16
- data/spec/spec_helper.rb +10 -5
- data/spec/vcr_cassetes/19133_2005.yml +42 -50
- data/spec/vcr_cassetes/cc_dir_10005_2019.yml +89 -158
- data/spec/vcr_cassetes/ecma_6.yml +473 -0
- data/spec/vcr_cassetes/fisp_140.yml +34 -2736
- data/spec/vcr_cassetes/gb_t_20223_2006.yml +18 -14
- data/spec/vcr_cassetes/hist_cmbined_included.yml +105 -0
- data/spec/vcr_cassetes/iec_combined_included.yml +1290 -0
- data/spec/vcr_cassetes/ieee_528_2019.yml +59 -49
- data/spec/vcr_cassetes/iho_b_11.yml +8 -9
- data/spec/vcr_cassetes/iso_111111119115_1.yml +8 -9
- data/spec/vcr_cassetes/iso_19115.yml +18 -18
- data/spec/vcr_cassetes/iso_19115_1.yml +42 -59
- data/spec/vcr_cassetes/iso_19115_1_2.yml +83 -124
- data/spec/vcr_cassetes/iso_awi_24229.yml +42 -53
- data/spec/vcr_cassetes/iso_combined_applied.yml +361 -0
- data/spec/vcr_cassetes/iso_combined_included.yml +361 -0
- data/spec/vcr_cassetes/itu_combined_included.yml +1278 -0
- data/spec/vcr_cassetes/ogc_19_025r1.yml +22 -11237
- data/spec/vcr_cassetes/ogm_ami4ccm_1_0.yml +9 -9
- data/spec/vcr_cassetes/rfc_8341.yml +6 -59
- data/spec/vcr_cassetes/sp_800_38b.yml +34 -2606
- data/spec/vcr_cassetes/un_rtade_cefact_2004_32.yml +179 -150
- data/spec/vcr_cassetes/w3c_json_ld11.yml +29 -21
- metadata +58 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 47b3cd2f3a5066e5b9bd67b07f02f6811593210e53e16438e5e0ccf32275be11
|
4
|
+
data.tar.gz: 677a08b28aff3139512ddc4f37ba0b7cc98f871f3faa80dad3e8fcd224771089
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9379dace67bfc0ac7793b261b9c94306b1425e3794a9b66228cba139b9229b3326a93800da954f26de5c23020cf816655c05af85c592297cbe0b513cddfaa28
|
7
|
+
data.tar.gz: 4aaeca235b959c2ec05ce03660639acd65899fdf1af0e96e9ccb5bfa6b6d26a42b9dbb69f1168f7904d36bd29c958ab9cfec3c34a1dc9c107e11c811ec262db1
|
data/.github/workflows/macos.yml
CHANGED
@@ -26,6 +26,8 @@ jobs:
|
|
26
26
|
- name: Update gems
|
27
27
|
run: |
|
28
28
|
sudo gem install bundler --force
|
29
|
+
ruby -v | grep 2.5 && bundle config set build.debase --with-cflags="-Wno-error=implicit-function-declaration"
|
30
|
+
ruby -v | grep 2.5 && bundle config set build.ruby-debug-ide --with-cflags="-Wno-error=implicit-function-declaration"
|
29
31
|
bundle install --jobs 4 --retry 3
|
30
32
|
- name: Run specs
|
31
33
|
run: |
|
data/docs/README.adoc
CHANGED
@@ -62,6 +62,8 @@ e.g. `get("ISO 19115-1", "2014", all_parts: true)` is transformed into a referen
|
|
62
62
|
|
63
63
|
== Usage
|
64
64
|
|
65
|
+
=== Create DB
|
66
|
+
|
65
67
|
[source,ruby]
|
66
68
|
----
|
67
69
|
require "relaton"
|
@@ -93,7 +95,12 @@ db = Relaton::Db.new("globalcache", "localcache")
|
|
93
95
|
@local_db=#<Relaton::DbCache:0x007faabc8fa5c0 @dir="localcache", @ext="xml">,
|
94
96
|
@local_db_name="localcache",
|
95
97
|
...
|
98
|
+
----
|
99
|
+
|
100
|
+
=== Fetch documens
|
96
101
|
|
102
|
+
[source,ruby]
|
103
|
+
----
|
97
104
|
x = db.fetch("IEEE 19011")
|
98
105
|
[relaton-ieee] ("IEEE 19011") fetching...
|
99
106
|
[relaton-ieee] WARNING: no match found online for IEEE 19011. The code must be exactly like it is on the standards website.
|
@@ -116,10 +123,72 @@ x = db.fetch("ISO 19115", nil, all_parts: true)
|
|
116
123
|
[relaton-iso] ("ISO 19115") found ISO 19115 (all parts)
|
117
124
|
=> #<RelatonIsoBib::IsoBibliographicItem:0x007fb1d0ae8bf0
|
118
125
|
...
|
126
|
+
----
|
127
|
+
|
128
|
+
=== Fetch combined documents
|
129
|
+
|
130
|
+
This functionality works only for ISO, IEC, ITU, and NIST documents.
|
131
|
+
|
132
|
+
==== Fetch included documents
|
133
|
+
[source,ruby]
|
134
|
+
----
|
135
|
+
bib = db.fetch "ISO 19115-1 + Amd 1"
|
136
|
+
[relaton-iso] ("ISO 19115-1") fetching...
|
137
|
+
[relaton-iso] ("ISO 19115-1") found ISO 19115-1:2014
|
138
|
+
[relaton-iso] ("ISO 19115-1/Amd 1") fetching...
|
139
|
+
[relaton-iso] ("ISO 19115-1/Amd 1") found ISO 19115-1:2014/Amd 1:2018
|
140
|
+
=> #<RelatonIsoBib::IsoBibliographicItem:0x007f95a929a748
|
141
|
+
|
142
|
+
bib.docidentifier[0].id
|
143
|
+
=> "ISO 19115-1 + Amd 1"
|
144
|
+
|
145
|
+
bib.relation[0].type
|
146
|
+
=> "updates"
|
147
|
+
|
148
|
+
bib.relation[0].bibitem.docidentifier[0].id
|
149
|
+
=> "ISO 19115-1"
|
150
|
+
|
151
|
+
bib.relation[1].type
|
152
|
+
=> "derivedFrom"
|
153
|
+
|
154
|
+
bib.relation[1].bibitem.docidentifier[0].id
|
155
|
+
=> "ISO 19115-1/Amd 1:2018"
|
156
|
+
|
157
|
+
bib.docidentifier[0].id
|
158
|
+
=> "ISO 19115-1, Amd 1"
|
159
|
+
|
160
|
+
bib.relation[0].type
|
161
|
+
=> "updates"
|
119
162
|
|
163
|
+
bib.relation[0].bibitem.docidentifier[0].id
|
164
|
+
=> "ISO 19115-1"
|
165
|
+
|
166
|
+
bib.relation[1].type
|
167
|
+
=> "complements"
|
168
|
+
|
169
|
+
bib.relation[1].description
|
170
|
+
=> "amendment"
|
171
|
+
|
172
|
+
bib.relation[1].bibitem.docidentifier[0].id
|
173
|
+
=> "ISO 19115-1/Amd 1:2018"
|
174
|
+
----
|
175
|
+
|
176
|
+
==== Fetch applied documents
|
177
|
+
[source,ruby]
|
178
|
+
----
|
179
|
+
bib = db.fetch "ISO 19115-1, Amd 1"
|
180
|
+
----
|
181
|
+
|
182
|
+
=== Get document type
|
183
|
+
[source,ruby]
|
184
|
+
----
|
120
185
|
db.docid_type("CN(GB/T 1.1)")
|
121
186
|
=> ["Chinese Standard", "GB/T 1.1"]
|
187
|
+
----
|
122
188
|
|
189
|
+
=== Serializing
|
190
|
+
[source,ruby]
|
191
|
+
----
|
123
192
|
x.to_xml
|
124
193
|
=> "<bibitem id="ISO19115(allparts)" type="standard">
|
125
194
|
...
|
@@ -146,11 +215,14 @@ db.load_entry("ISO(ISO 19011)")
|
|
146
215
|
=> "<bibdata type="standard">
|
147
216
|
...
|
148
217
|
<?bibdata>"
|
218
|
+
----
|
149
219
|
|
220
|
+
=== Entry manipulation
|
221
|
+
[source,ruby]
|
222
|
+
----
|
150
223
|
db.save_entry("ISO(ISO 19011)", nil)
|
151
224
|
=> nil
|
152
225
|
|
153
226
|
db.load_entry("ISO(ISO 19011)")
|
154
227
|
=> nil
|
155
|
-
|
156
228
|
----
|
data/lib/relaton/config.rb
CHANGED
data/lib/relaton/db.rb
CHANGED
@@ -28,9 +28,34 @@ module Relaton
|
|
28
28
|
# RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem]
|
29
29
|
def fetch(code, year = nil, opts = {})
|
30
30
|
stdclass = standard_class(code) || return
|
31
|
+
cd = combine_doc code, year, opts, stdclass
|
32
|
+
return cd if cd
|
33
|
+
|
31
34
|
check_bibliocache(code, year, opts, stdclass)
|
32
35
|
end
|
33
36
|
|
37
|
+
def combine_doc(code, year, opts, stdclass)
|
38
|
+
if (refs = code.split " + ").size > 1
|
39
|
+
reltype = "derivedFrom"
|
40
|
+
reldesc = nil
|
41
|
+
elsif (refs = code.split ", ").size > 1
|
42
|
+
reltype = "complements"
|
43
|
+
reldesc = RelatonBib::FormattedString.new content: "amendment"
|
44
|
+
else return
|
45
|
+
end
|
46
|
+
|
47
|
+
doc = @registry.processors[stdclass].hash_to_bib docid: { id: code }
|
48
|
+
ref = refs[0]
|
49
|
+
updates = check_bibliocache(ref, year, opts, stdclass)
|
50
|
+
doc.relation << RelatonBib::DocumentRelation.new(bibitem: updates, type: "updates") if updates
|
51
|
+
refs[1..-1].each_with_object(doc) do |c, d|
|
52
|
+
bib = check_bibliocache("#{ref}/#{c}", year, opts, stdclass)
|
53
|
+
if bib
|
54
|
+
d.relation << RelatonBib::DocumentRelation.new(type: reltype, description: reldesc, bibitem: bib)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
34
59
|
# @param code [String]
|
35
60
|
# @param year [String, NilClass]
|
36
61
|
# @param stdclass [Symbol, NilClass]
|
@@ -40,9 +65,8 @@ module Relaton
|
|
40
65
|
@registry.processors.each do |name, processor|
|
41
66
|
std = name if processor.prefix == stdclass
|
42
67
|
end
|
43
|
-
unless std
|
44
|
-
|
45
|
-
end
|
68
|
+
std = standard_class(code) or return nil unless std
|
69
|
+
|
46
70
|
check_bibliocache(code, year, opts, std)
|
47
71
|
end
|
48
72
|
|
@@ -97,9 +121,9 @@ module Relaton
|
|
97
121
|
m << v.prefix
|
98
122
|
end
|
99
123
|
warn <<~WARN
|
100
|
-
|
101
|
-
|
102
|
-
|
124
|
+
#{code} does not have a recognised prefix: #{allowed.join(', ')}.
|
125
|
+
See https://github.com/relaton/relaton/ for instructions on prefixing and wrapping document identifiers to disambiguate them.
|
126
|
+
WARN
|
103
127
|
end
|
104
128
|
|
105
129
|
# TODO: i18n
|
@@ -133,8 +157,8 @@ module Relaton
|
|
133
157
|
# @return [NilClass, RelatonIsoBib::IsoBibliographicItem,
|
134
158
|
# RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
|
135
159
|
# RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem]
|
136
|
-
def bib_retval(entry, stdclass,
|
137
|
-
entry
|
160
|
+
def bib_retval(entry, stdclass, _id)
|
161
|
+
entry.match?(/^not_found/) ? nil : @registry.processors[stdclass].from_xml(entry)
|
138
162
|
end
|
139
163
|
|
140
164
|
# @param code [String]
|
@@ -145,7 +169,7 @@ module Relaton
|
|
145
169
|
# RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
|
146
170
|
# RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem,
|
147
171
|
# RelatonOgc::OgcBibliographicItem, RelatonCalconnect::CcBibliographicItem]
|
148
|
-
def check_bibliocache(code, year, opts, stdclass)
|
172
|
+
def check_bibliocache(code, year, opts, stdclass) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/MethodLength,Metrics/PerceivedComplexity
|
149
173
|
id, searchcode = std_id(code, year, opts, stdclass)
|
150
174
|
yaml = @static_db[id]
|
151
175
|
return @registry.processors[stdclass].hash_to_bib YAML.safe_load(yaml) if yaml
|
@@ -176,7 +200,7 @@ module Relaton
|
|
176
200
|
# @param db [Relaton::DbCache,`NilClass]
|
177
201
|
# @param id [String] docid
|
178
202
|
# @return [String]
|
179
|
-
def new_bib_entry(code, year, opts, stdclass, **args)
|
203
|
+
def new_bib_entry(code, year, opts, stdclass, **args) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
180
204
|
bib = @registry.processors[stdclass].get(code, year, opts)
|
181
205
|
bib_id = bib&.docidentifier&.first&.id
|
182
206
|
|
data/lib/relaton/db_cache.rb
CHANGED
@@ -26,7 +26,7 @@ module Relaton
|
|
26
26
|
prefix_dir = "#{@dir}/#{prefix(key)}"
|
27
27
|
FileUtils::mkdir_p prefix_dir unless Dir.exist? prefix_dir
|
28
28
|
set_version prefix_dir
|
29
|
-
|
29
|
+
file_safe_write "#{filename(key)}.#{ext(value)}", value
|
30
30
|
end
|
31
31
|
|
32
32
|
# @param value [String]
|
@@ -65,7 +65,7 @@ module Relaton
|
|
65
65
|
value = self[key]
|
66
66
|
return unless value
|
67
67
|
|
68
|
-
if value
|
68
|
+
if value.match? /^not_found/
|
69
69
|
value.match(/\d{4}-\d{2}-\d{2}/).to_s
|
70
70
|
else
|
71
71
|
doc = Nokogiri::XML value
|
@@ -106,7 +106,7 @@ module Relaton
|
|
106
106
|
def set_version(fdir)
|
107
107
|
file_version = "#{fdir}/version"
|
108
108
|
unless File.exist? file_version
|
109
|
-
|
109
|
+
file_safe_write file_version, grammar_hash(fdir)
|
110
110
|
end
|
111
111
|
self
|
112
112
|
end
|
@@ -159,7 +159,7 @@ module Relaton
|
|
159
159
|
def filename(key)
|
160
160
|
prefcode = key.downcase.match /^(?<prefix>[^\(]+)\((?<code>[^\)]+)/
|
161
161
|
fn = if prefcode
|
162
|
-
"#{prefcode[:prefix]}/#{prefcode[:code].gsub(/[-:\s\/\()]/, '_').squeeze(
|
162
|
+
"#{prefcode[:prefix]}/#{prefcode[:code].gsub(/[-:\s\/\()]/, '_').squeeze('_')}"
|
163
163
|
else
|
164
164
|
key.gsub(/[-:\s]/, "_")
|
165
165
|
end
|
@@ -189,6 +189,15 @@ module Relaton
|
|
189
189
|
key.downcase.match(/^[^\(]+(?=\()/).to_s
|
190
190
|
end
|
191
191
|
|
192
|
+
# @param file [String]
|
193
|
+
# @content [String]
|
194
|
+
def file_safe_write(file, content)
|
195
|
+
File.open file, File::RDWR | File::CREAT, encoding: "UTF-8" do |f|
|
196
|
+
Timeout.timeout(1) { f.flock File::LOCK_EX }
|
197
|
+
f.write content
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
192
201
|
class << self
|
193
202
|
private
|
194
203
|
|
@@ -209,7 +218,7 @@ module Relaton
|
|
209
218
|
# local_cache: local cache name; none created if nil; "relaton" created
|
210
219
|
# if empty global_cache: boolean to create global_cache
|
211
220
|
# flush_caches: flush caches
|
212
|
-
def init_bib_caches(opts)
|
221
|
+
def init_bib_caches(opts) # rubocop:disable Metrics/CyclomaticComplexity
|
213
222
|
globalname = global_bibliocache_name if opts[:global_cache]
|
214
223
|
localname = local_bibliocache_name(opts[:local_cache])
|
215
224
|
localname = "relaton" if localname&.empty?
|
data/lib/relaton/registry.rb
CHANGED
@@ -8,7 +8,7 @@ module Relaton
|
|
8
8
|
SUPPORTED_GEMS = %w[
|
9
9
|
relaton_gb relaton_iec relaton_ietf relaton_iso relaton_itu relaton_nist
|
10
10
|
relaton_ogc relaton_calconnect relaton_omg relaton_un relaton_w3c
|
11
|
-
relaton_ieee relaton_iho relaton_bipm
|
11
|
+
relaton_ieee relaton_iho relaton_bipm relaton_ecma
|
12
12
|
].freeze
|
13
13
|
|
14
14
|
include Singleton
|
@@ -57,9 +57,10 @@ module Relaton
|
|
57
57
|
# Find processor by type
|
58
58
|
#
|
59
59
|
# @param type [String]
|
60
|
-
# @return [RelatonIso::Processor, RelatonIec::Processor,
|
61
|
-
# RelatonIetf::Processot, RelatonItu::Processor,
|
62
|
-
#
|
60
|
+
# @return [RelatonIso::Processor, RelatonIec::Processor,
|
61
|
+
# RelatonNist::Processor, RelatonIetf::Processot, RelatonItu::Processor,
|
62
|
+
# RelatonGb::Processor, RelatonOgc::Processor,
|
63
|
+
# RelatonCalconnect::Processor]
|
63
64
|
def by_type(type)
|
64
65
|
processors.values.detect { |v| v.prefix == type&.upcase }
|
65
66
|
end
|
data/lib/relaton/version.rb
CHANGED
data/relaton.gemspec
CHANGED
@@ -30,20 +30,21 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
31
31
|
|
32
32
|
# spec.add_dependency "algoliasearch"
|
33
|
-
spec.add_dependency "relaton-bipm", "~> 1.
|
34
|
-
spec.add_dependency "relaton-calconnect", "~> 1.
|
35
|
-
spec.add_dependency "relaton-
|
36
|
-
spec.add_dependency "relaton-
|
37
|
-
spec.add_dependency "relaton-
|
38
|
-
spec.add_dependency "relaton-
|
39
|
-
spec.add_dependency "relaton-
|
40
|
-
spec.add_dependency "relaton-
|
41
|
-
spec.add_dependency "relaton-
|
42
|
-
spec.add_dependency "relaton-
|
43
|
-
spec.add_dependency "relaton-
|
44
|
-
spec.add_dependency "relaton-
|
45
|
-
spec.add_dependency "relaton-
|
46
|
-
spec.add_dependency "relaton-
|
33
|
+
spec.add_dependency "relaton-bipm", "~> 1.7.0"
|
34
|
+
spec.add_dependency "relaton-calconnect", "~> 1.7.0"
|
35
|
+
spec.add_dependency "relaton-ecma", "1.7.pre1"
|
36
|
+
spec.add_dependency "relaton-gb", "~> 1.7.0"
|
37
|
+
spec.add_dependency "relaton-iec", ">= 1.7.3"
|
38
|
+
spec.add_dependency "relaton-ieee", "~> 1.7.0"
|
39
|
+
spec.add_dependency "relaton-ietf", "~> 1.7.0"
|
40
|
+
spec.add_dependency "relaton-iho", "~> 1.7.0"
|
41
|
+
spec.add_dependency "relaton-iso", ">= 1.7.1"
|
42
|
+
spec.add_dependency "relaton-itu", ">= 1.7.2"
|
43
|
+
spec.add_dependency "relaton-nist", ">= 1.7.1"
|
44
|
+
spec.add_dependency "relaton-ogc", "~> 1.7.0"
|
45
|
+
spec.add_dependency "relaton-omg", "~> 1.7.0"
|
46
|
+
spec.add_dependency "relaton-un", "~> 1.7.0"
|
47
|
+
spec.add_dependency "relaton-w3c", "~> 1.7.0"
|
47
48
|
|
48
49
|
spec.add_development_dependency "byebug", "~> 11.0"
|
49
50
|
spec.add_development_dependency "debase"
|
@@ -1,13 +1,38 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
require "timeout"
|
3
|
+
|
1
4
|
RSpec.describe Relaton::DbCache do
|
2
5
|
it "creates default caches" do
|
3
6
|
cache_path = File.expand_path("~/.relaton/cache")
|
4
7
|
FileUtils.mv cache_path, "relaton1/cache", force: true
|
5
8
|
FileUtils.rm_rf %w(relaton)
|
6
9
|
Relaton::DbCache.init_bib_caches(
|
7
|
-
global_cache: true, local_cache: "", flush_caches: true
|
10
|
+
global_cache: true, local_cache: "", flush_caches: true
|
8
11
|
)
|
9
12
|
expect(File.exist?(cache_path)).to be true
|
10
13
|
expect(File.exist?("relaton")).to be true
|
11
14
|
FileUtils.mv "relaton1/cache", cache_path if File.exist? "relaton1"
|
12
15
|
end
|
16
|
+
|
17
|
+
it "write same file by concurent processes" do
|
18
|
+
dir = "testcache/iso"
|
19
|
+
FileUtils.mkdir_p dir unless File.exist? dir
|
20
|
+
file_name = File.join dir, "iso_123.xml"
|
21
|
+
file = File.open file_name, File::RDWR | File::CREAT, encoding: "UTF-8"
|
22
|
+
file.flock File::LOCK_EX
|
23
|
+
command = <<~RBY
|
24
|
+
require "relaton"
|
25
|
+
cache = Relaton::DbCache.new "testcache"
|
26
|
+
cache["ISO(ISO 123)"] = "test 1"
|
27
|
+
RBY
|
28
|
+
pid = spawn RbConfig.ruby, "-e #{command}"
|
29
|
+
sleep 0.1
|
30
|
+
file.write "test 2"
|
31
|
+
file.flock File::LOCK_UN
|
32
|
+
file.close
|
33
|
+
Process.waitpid pid, 0
|
34
|
+
expect($?.exitstatus).to eq 0
|
35
|
+
expect(File.read(file_name)).to eq "test 1"
|
36
|
+
FileUtils.rm_rf "testcache"
|
37
|
+
end
|
13
38
|
end
|
@@ -2,13 +2,13 @@ RSpec.describe Relaton::Registry do
|
|
2
2
|
it "outputs backend not present" do
|
3
3
|
stub_const "Relaton::Registry::SUPPORTED_GEMS", ["not_supported_gem"]
|
4
4
|
expect { Relaton::Registry.clone.instance }.to output(
|
5
|
-
/backend not_supported_gem not present
|
5
|
+
/backend not_supported_gem not present/
|
6
6
|
).to_stdout
|
7
7
|
end
|
8
8
|
|
9
9
|
it "finds ISO processor" do
|
10
|
-
expect(Relaton::Registry.instance.find_processor("relaton_iso"))
|
11
|
-
to be_instance_of RelatonIso::Processor
|
10
|
+
expect(Relaton::Registry.instance.find_processor("relaton_iso"))
|
11
|
+
.to be_instance_of RelatonIso::Processor
|
12
12
|
end
|
13
13
|
|
14
14
|
it "returns supported processors" do
|
@@ -70,4 +70,8 @@ RSpec.describe Relaton::Registry do
|
|
70
70
|
it "finds processor by type" do
|
71
71
|
expect(Relaton::Registry.instance.by_type("BIPM")).to be_instance_of RelatonBipm::Processor
|
72
72
|
end
|
73
|
+
|
74
|
+
it "finds processor by type" do
|
75
|
+
expect(Relaton::Registry.instance.by_type("ECMA")).to be_instance_of RelatonEcma::Processor
|
76
|
+
end
|
73
77
|
end
|
data/spec/relaton_spec.rb
CHANGED
@@ -5,7 +5,9 @@ RSpec.describe Relaton::Db do
|
|
5
5
|
end
|
6
6
|
|
7
7
|
it "rejects an illegal reference prefix" do
|
8
|
-
expect { @db.fetch("XYZ XYZ", nil, {}) }.to output(
|
8
|
+
expect { @db.fetch("XYZ XYZ", nil, {}) }.to output(
|
9
|
+
/does not have a recognised prefix/
|
10
|
+
).to_stderr
|
9
11
|
end
|
10
12
|
|
11
13
|
context "gets an ISO reference" do
|
@@ -13,13 +15,16 @@ RSpec.describe Relaton::Db do
|
|
13
15
|
VCR.use_cassette "iso_19115_1" do
|
14
16
|
bib = @db.fetch("ISO 19115-1", nil, {})
|
15
17
|
expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
|
16
|
-
expect(bib.to_xml(bibdata: true)).to include "<project-number>
|
18
|
+
expect(bib.to_xml(bibdata: true)).to include "<project-number>"\
|
19
|
+
"ISO 19115</project-number>"
|
17
20
|
expect(File.exist?("testcache")).to be true
|
18
21
|
expect(File.exist?("testcache2")).to be true
|
19
22
|
testcache = Relaton::DbCache.new "testcache"
|
20
|
-
expect(testcache["ISO(ISO 19115-1)"]).to include "<project-number>
|
23
|
+
expect(testcache["ISO(ISO 19115-1)"]).to include "<project-number>"\
|
24
|
+
"ISO 19115</project-number>"
|
21
25
|
testcache = Relaton::DbCache.new "testcache2"
|
22
|
-
expect(testcache["ISO(ISO 19115-1)"]).to include "<project-number>
|
26
|
+
expect(testcache["ISO(ISO 19115-1)"]).to include "<project-number>"\
|
27
|
+
"ISO 19115</project-number>"
|
23
28
|
end
|
24
29
|
bib = @db.fetch("ISO 19115-1", nil, {})
|
25
30
|
expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
|
@@ -29,9 +34,12 @@ RSpec.describe Relaton::Db do
|
|
29
34
|
VCR.use_cassette "19133_2005" do
|
30
35
|
bib = @db.fetch("ISO 19133:2005")
|
31
36
|
expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
|
32
|
-
expect(bib.to_xml).to include '<bibitem id="ISO19133-2005"
|
37
|
+
expect(bib.to_xml).to include '<bibitem id="ISO19133-2005" '\
|
38
|
+
'type="standard">'
|
33
39
|
testcache = Relaton::DbCache.new "testcache"
|
34
|
-
expect(
|
40
|
+
expect(
|
41
|
+
testcache.valid_entry?("ISO(ISO 19133:2005)", Date.today.year.to_s)
|
42
|
+
).to eq Date.today.year.to_s
|
35
43
|
end
|
36
44
|
end
|
37
45
|
|
@@ -60,6 +68,13 @@ RSpec.describe Relaton::Db do
|
|
60
68
|
end
|
61
69
|
|
62
70
|
context "NIST references" do
|
71
|
+
before(:each) do
|
72
|
+
nist_fr = /\.relaton\/nist\/pubs-export\.zip/
|
73
|
+
expect(File).to receive(:exist?).with(nist_fr).and_return false
|
74
|
+
expect(File).to receive(:exist?).and_call_original.at_least :once
|
75
|
+
# expect(FileUtils).to receive(:mv).with kind_of(String), nist_fr
|
76
|
+
end
|
77
|
+
|
63
78
|
it "gets FISP" do
|
64
79
|
VCR.use_cassette "fisp_140" do
|
65
80
|
bib = @db.fetch "NIST FIPS 140"
|
@@ -119,13 +134,19 @@ RSpec.describe Relaton::Db do
|
|
119
134
|
VCR.use_cassette "gb_t_20223_2006" do
|
120
135
|
bib = @db.fetch "CN(GB/T 20223)", "2006", {}
|
121
136
|
expect(bib).to be_instance_of RelatonGb::GbBibliographicItem
|
122
|
-
expect(bib.to_xml(bibdata: true)).to include
|
137
|
+
expect(bib.to_xml(bibdata: true)).to include <<~XML
|
138
|
+
<project-number>GB/T 20223</project-number>
|
139
|
+
XML
|
123
140
|
expect(File.exist?("testcache")).to be true
|
124
141
|
expect(File.exist?("testcache2")).to be true
|
125
142
|
testcache = Relaton::DbCache.new "testcache"
|
126
|
-
expect(testcache["CN(GB/T 20223:2006)"]).to include
|
143
|
+
expect(testcache["CN(GB/T 20223:2006)"]).to include <<~XML
|
144
|
+
<project-number>GB/T 20223</project-number>
|
145
|
+
XML
|
127
146
|
testcache = Relaton::DbCache.new "testcache2"
|
128
|
-
expect(testcache["CN(GB/T 20223:2006)"]).to include
|
147
|
+
expect(testcache["CN(GB/T 20223:2006)"]).to include <<~XML
|
148
|
+
<project-number>GB/T 20223</project-number>
|
149
|
+
XML
|
129
150
|
end
|
130
151
|
end
|
131
152
|
|
@@ -133,13 +154,19 @@ RSpec.describe Relaton::Db do
|
|
133
154
|
VCR.use_cassette "gb_t_20223_2006" do
|
134
155
|
bib = @db.fetch "CN(GB/T 20223-2006)", nil, {}
|
135
156
|
expect(bib).to be_instance_of RelatonGb::GbBibliographicItem
|
136
|
-
expect(bib.to_xml(bibdata: true)).to include
|
157
|
+
expect(bib.to_xml(bibdata: true)).to include <<~XML
|
158
|
+
<project-number>GB/T 20223</project-number>
|
159
|
+
XML
|
137
160
|
expect(File.exist?("testcache")).to be true
|
138
161
|
expect(File.exist?("testcache2")).to be true
|
139
162
|
testcache = Relaton::DbCache.new "testcache"
|
140
|
-
expect(testcache["CN(GB/T 20223:2006)"]).to include
|
163
|
+
expect(testcache["CN(GB/T 20223:2006)"]).to include <<~XML
|
164
|
+
<project-number>GB/T 20223</project-number>
|
165
|
+
XML
|
141
166
|
testcache = Relaton::DbCache.new "testcache2"
|
142
|
-
expect(testcache["CN(GB/T 20223:2006)"]).to include
|
167
|
+
expect(testcache["CN(GB/T 20223:2006)"]).to include <<~XML
|
168
|
+
<project-number>GB/T 20223</project-number>
|
169
|
+
XML
|
143
170
|
end
|
144
171
|
end
|
145
172
|
end
|
@@ -152,9 +179,11 @@ RSpec.describe Relaton::Db do
|
|
152
179
|
expect(File.exist?("testcache")).to be true
|
153
180
|
expect(File.exist?("testcache2")).to be true
|
154
181
|
testcache = Relaton::DbCache.new "testcache"
|
155
|
-
expect(testcache["IETF(RFC 8341)"]).to include "<docidentifier
|
182
|
+
expect(testcache["IETF(RFC 8341)"]).to include "<docidentifier "\
|
183
|
+
"type=\"IETF\">RFC 8341</docidentifier>"
|
156
184
|
testcache = Relaton::DbCache.new "testcache2"
|
157
|
-
expect(testcache["IETF(RFC 8341)"]).to include "<docidentifier
|
185
|
+
expect(testcache["IETF(RFC 8341)"]).to include "<docidentifier "\
|
186
|
+
"type=\"IETF\">RFC 8341</docidentifier>"
|
158
187
|
end
|
159
188
|
end
|
160
189
|
|
@@ -166,6 +195,13 @@ RSpec.describe Relaton::Db do
|
|
166
195
|
end
|
167
196
|
|
168
197
|
it "get Calconnect refrence and cache it" do
|
198
|
+
cc_fr = /\.relaton\/calconnect\/bibliography\.yml/
|
199
|
+
expect(File).to receive(:exist?).with(cc_fr).and_return false
|
200
|
+
expect(File).to receive(:exist?).with(/etag\.txt/).and_return false
|
201
|
+
expect(File).to receive(:exist?).and_call_original.at_least :once
|
202
|
+
expect(File).to receive(:write).with(cc_fr, kind_of(String), kind_of(Hash))
|
203
|
+
.at_most :once
|
204
|
+
expect(File).to receive(:write).and_call_original.at_least :once
|
169
205
|
VCR.use_cassette "cc_dir_10005_2019", match_requests_on: [:path] do
|
170
206
|
bib = @db.fetch "CC/DIR 10005:2019", nil, {}
|
171
207
|
expect(bib).to be_instance_of RelatonCalconnect::CcBibliographicItem
|
@@ -187,6 +223,11 @@ RSpec.describe Relaton::Db do
|
|
187
223
|
end
|
188
224
|
|
189
225
|
it "get W3C reference" do
|
226
|
+
w3c_fr = /\.relaton\/w3c\/bibliography\.yml/
|
227
|
+
expect(File).to receive(:exist?).with(w3c_fr).and_return false
|
228
|
+
expect(File).to receive(:exist?).and_call_original.at_least :once
|
229
|
+
expect(File).to receive(:write).with w3c_fr, kind_of(String), kind_of(Hash)
|
230
|
+
# expect(File).to receive(:write).and_call_original.at_least :once
|
190
231
|
VCR.use_cassette "w3c_json_ld11" do
|
191
232
|
bib = @db.fetch "W3C JSON-LD 1.1", nil, {}
|
192
233
|
expect(bib).to be_instance_of RelatonW3c::W3cBibliographicItem
|
@@ -207,6 +248,89 @@ RSpec.describe Relaton::Db do
|
|
207
248
|
end
|
208
249
|
end
|
209
250
|
|
251
|
+
it "get ECMA reference" do
|
252
|
+
VCR.use_cassette "ecma_6" do
|
253
|
+
bib = @db.fetch "ECMA-6"
|
254
|
+
expect(bib).to be_instance_of RelatonBib::BibliographicItem
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
context "get combined documents" do
|
259
|
+
context "ISO" do
|
260
|
+
it "included" do
|
261
|
+
VCR.use_cassette "iso_combined_included" do
|
262
|
+
bib = @db.fetch "ISO 19115-1 + Amd 1"
|
263
|
+
expect(bib.docidentifier[0].id).to eq "ISO 19115-1 + Amd 1"
|
264
|
+
expect(bib.relation[0].type).to eq "updates"
|
265
|
+
expect(bib.relation[0].bibitem.docidentifier[0].id).to eq "ISO 19115-1"
|
266
|
+
expect(bib.relation[1].type).to eq "derivedFrom"
|
267
|
+
expect(bib.relation[1].description).to be_nil
|
268
|
+
expect(bib.relation[1].bibitem.docidentifier[0].id).to eq "ISO 19115-1/Amd 1:2018"
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
it "applied" do
|
273
|
+
VCR.use_cassette "iso_combined_applied" do
|
274
|
+
bib = @db.fetch "ISO 19115-1, Amd 1"
|
275
|
+
expect(bib.docidentifier[0].id).to eq "ISO 19115-1, Amd 1"
|
276
|
+
expect(bib.relation[0].type).to eq "updates"
|
277
|
+
expect(bib.relation[0].bibitem.docidentifier[0].id).to eq "ISO 19115-1"
|
278
|
+
expect(bib.relation[1].type).to eq "complements"
|
279
|
+
expect(bib.relation[1].description.content).to eq "amendment"
|
280
|
+
expect(bib.relation[1].bibitem.docidentifier[0].id).to eq "ISO 19115-1/Amd 1:2018"
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
context "IEC" do
|
286
|
+
it "included" do
|
287
|
+
VCR.use_cassette "iec_combined_included" do
|
288
|
+
bib = @db.fetch "IEC 60027-1, Amd 1, Amd 2"
|
289
|
+
expect(bib.docidentifier[0].id).to eq "IEC 60027-1, Amd 1, Amd 2"
|
290
|
+
expect(bib.relation[0].type).to eq "updates"
|
291
|
+
expect(bib.relation[0].bibitem.docidentifier[0].id).to eq "IEC 60027-1"
|
292
|
+
expect(bib.relation[1].type).to eq "complements"
|
293
|
+
expect(bib.relation[1].description.content).to eq "amendment"
|
294
|
+
expect(bib.relation[1].bibitem.docidentifier[0].id).to eq "IEC 60027-1/AMD1:1997"
|
295
|
+
expect(bib.relation[2].type).to eq "complements"
|
296
|
+
expect(bib.relation[2].description.content).to eq "amendment"
|
297
|
+
expect(bib.relation[2].bibitem.docidentifier[0].id).to eq "IEC 60027-1/AMD2:2005"
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
context "ITU" do
|
303
|
+
it "included" do
|
304
|
+
VCR.use_cassette "itu_combined_included" do
|
305
|
+
bib = @db.fetch "ITU-T G.989.2, Amd 1, Amd 2"
|
306
|
+
expect(bib.docidentifier[0].id).to eq "ITU-T G.989.2, Amd 1, Amd 2"
|
307
|
+
expect(bib.relation[0].type).to eq "updates"
|
308
|
+
expect(bib.relation[0].bibitem.docidentifier[0].id).to eq "ITU-T G.989.2"
|
309
|
+
expect(bib.relation[1].type).to eq "complements"
|
310
|
+
expect(bib.relation[1].description.content).to eq "amendment"
|
311
|
+
expect(bib.relation[1].bibitem.docidentifier[0].id).to eq "ITU-T G.989.2/Amd 1"
|
312
|
+
expect(bib.relation[2].type).to eq "complements"
|
313
|
+
expect(bib.relation[2].description.content).to eq "amendment"
|
314
|
+
expect(bib.relation[2].bibitem.docidentifier[0].id).to eq "ITU-T G.989.2/Amd 2"
|
315
|
+
end
|
316
|
+
end
|
317
|
+
end
|
318
|
+
|
319
|
+
context "HIST" do
|
320
|
+
it "included" do
|
321
|
+
VCR.use_cassette "hist_cmbined_included" do
|
322
|
+
bib = @db.fetch "NIST SP 800-38A, Add"
|
323
|
+
expect(bib.docidentifier[0].id).to eq "NIST SP 800-38A, Add"
|
324
|
+
expect(bib.relation[0].type).to eq "updates"
|
325
|
+
expect(bib.relation[0].bibitem.docidentifier[0].id).to eq "SP 800-38A"
|
326
|
+
expect(bib.relation[1].type).to eq "complements"
|
327
|
+
expect(bib.relation[1].description.content).to eq "amendment"
|
328
|
+
expect(bib.relation[1].bibitem.docidentifier[0].id).to eq "SP 800-38A-Add"
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
210
334
|
context "version control" do
|
211
335
|
before(:each) { @db.save_entry "iso(test_key)", value: "test_value" }
|
212
336
|
|
@@ -222,8 +346,10 @@ RSpec.describe Relaton::Db do
|
|
222
346
|
expect(File.exist?("testcache")).to be true
|
223
347
|
expect(File.exist?("testcache2")).to be true
|
224
348
|
processor = double
|
225
|
-
expect(processor).to receive(:grammar_hash).and_return("new_version")
|
226
|
-
|
349
|
+
expect(processor).to receive(:grammar_hash).and_return("new_version")
|
350
|
+
.exactly(2).times
|
351
|
+
expect(Relaton::Registry.instance).to receive(:by_type)
|
352
|
+
.and_return(processor).exactly(2).times
|
227
353
|
db = Relaton::Db.new "testcache", "testcache2"
|
228
354
|
testcache = db.instance_variable_get :@db
|
229
355
|
expect(testcache.all).not_to be_any
|