relaton 0.5.5 → 0.5.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
  SHA1:
3
- metadata.gz: 6f5141e3248627b6049adc55acefad59782139a7
4
- data.tar.gz: aea95c57dd6e0c8dcc6ff0a6ffb7776ab18005a9
3
+ metadata.gz: 333eee1b308d8d037986579ebf16c9c4cd74be03
4
+ data.tar.gz: 69aaadc86f93645ee19a31a76bccb1e63315f4e1
5
5
  SHA512:
6
- metadata.gz: 9c5cb8cee13c41e13e96f2cffe4eee9d7b62ad0233f6cb7ce62e4ed22622b9b37963b25304c56b2dc36b52ce47b9d92753039a0ab4f77d56c9c4192fc300e791
7
- data.tar.gz: 99b568d4c204bc1e8fe4d3ddbe8fde2185dc70f3da411183bd265112567ccf19defc4e89312f3c7e91d1308f763d55bdcef2084871178f6d4db9f81dbe856299
6
+ metadata.gz: 7d7aa5f35ade21aeb17e360cf396eaba3705de1253f251cc70a79775d555b12a7f3ac19b5b4035eb8a6516d4a44680107650d3a1d9aeea3cae46682aa9b48d09
7
+ data.tar.gz: 55979c2c2f8183ef75224a3d6112a8f8737610667be7718794ce1f345f29dc7ff73185caf4970c9e3114e59d67458b606c41af7e9077eeb22b6899c1b39381fa
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton (0.5.5)
4
+ relaton (0.5.6)
5
5
  relaton-gb (~> 0.6.0)
6
6
  relaton-iec (~> 0.4.0)
7
7
  relaton-ietf (~> 0.6.0)
@@ -17,7 +17,7 @@ GEM
17
17
  public_suffix (>= 2.0.2, < 5.0)
18
18
  ast (2.4.0)
19
19
  byebug (10.0.2)
20
- cnccs (0.1.3)
20
+ cnccs (0.1.4)
21
21
  coderay (1.1.2)
22
22
  crack (0.4.3)
23
23
  safe_yaml (~> 1.0.0)
@@ -28,11 +28,11 @@ GEM
28
28
  docile (1.3.2)
29
29
  equivalent-xml (0.6.0)
30
30
  nokogiri (>= 1.4.3)
31
- faraday (0.15.4)
31
+ faraday (0.17.0)
32
32
  multipart-post (>= 1.2, < 3)
33
33
  ffi (1.11.1)
34
34
  formatador (0.2.5)
35
- gb-agencies (0.0.5)
35
+ gb-agencies (0.0.6)
36
36
  guard (2.15.0)
37
37
  formatador (>= 0.2.4)
38
38
  listen (>= 2.7, < 4.0)
@@ -48,7 +48,7 @@ GEM
48
48
  guard-compat (~> 1.1)
49
49
  rspec (>= 2.99.0, < 4.0)
50
50
  hashdiff (0.4.0)
51
- isoics (0.1.7)
51
+ isoics (0.1.8)
52
52
  json (2.2.0)
53
53
  listen (3.1.5)
54
54
  rb-fsevent (~> 0.9, >= 0.9.4)
@@ -80,31 +80,31 @@ GEM
80
80
  rb-fsevent (0.10.3)
81
81
  rb-inotify (0.10.0)
82
82
  ffi (~> 1.0)
83
- relaton-bib (0.3.8)
83
+ relaton-bib (0.3.9)
84
84
  addressable
85
85
  nokogiri
86
- relaton-gb (0.6.4)
86
+ relaton-gb (0.6.5)
87
87
  cnccs (~> 0.1.1)
88
88
  gb-agencies (~> 0.0.1)
89
89
  relaton-iso-bib (~> 0.3.0)
90
- relaton-iec (0.4.6)
90
+ relaton-iec (0.4.8)
91
91
  addressable
92
92
  relaton-iso-bib (~> 0.3.0)
93
- relaton-ietf (0.6.5)
93
+ relaton-ietf (0.6.6)
94
94
  relaton-bib (~> 0.3.0)
95
- relaton-iso (0.6.6)
95
+ relaton-iso (0.6.7)
96
96
  relaton-iec (~> 0.4.0)
97
97
  relaton-iso-bib (~> 0.3.0)
98
- relaton-iso-bib (0.3.7)
98
+ relaton-iso-bib (0.3.9)
99
99
  isoics (~> 0.1.6)
100
100
  relaton-bib (~> 0.3.0)
101
101
  ruby_deep_clone (~> 0.8.0)
102
- relaton-itu (0.3.4)
102
+ relaton-itu (0.3.5)
103
103
  relaton-iso-bib (~> 0.3.0)
104
- relaton-nist (0.3.5)
104
+ relaton-nist (0.3.6)
105
105
  relaton-bib (~> 0.3.0)
106
106
  rubyzip
107
- relaton-ogc (0.1.1)
107
+ relaton-ogc (0.1.2)
108
108
  faraday
109
109
  relaton-iso-bib (~> 0.3.0)
110
110
  rspec (3.8.0)
@@ -1,4 +1,4 @@
1
- # require "pstore"
1
+ require "yaml"
2
2
  require_relative "registry"
3
3
  require_relative "db_cache"
4
4
 
@@ -11,10 +11,12 @@ module Relaton
11
11
  def initialize(global_cache, local_cache)
12
12
  @registry = Relaton::Registry.instance
13
13
  # @registry.register_gems
14
- @db = open_cache_biblio(global_cache)
15
- @local_db = open_cache_biblio(local_cache, global: false)
14
+ @db = open_cache_biblio(global_cache, type: :global)
15
+ @local_db = open_cache_biblio(local_cache, type: :local)
16
16
  @db_name = global_cache
17
17
  @local_db_name = local_cache
18
+ static_db_name = File.expand_path "../relaton/static_cache", __dir__
19
+ @static_db = open_cache_biblio static_db_name
18
20
  end
19
21
 
20
22
  # The class of reference requested is determined by the prefix of the code:
@@ -26,7 +28,7 @@ module Relaton
26
28
  # RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
27
29
  # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem]
28
30
  def fetch(code, year = nil, opts = {})
29
- stdclass = standard_class(code) or return nil
31
+ stdclass = standard_class(code) || return
30
32
  check_bibliocache(code, year, opts, stdclass)
31
33
  end
32
34
 
@@ -96,7 +98,6 @@ module Relaton
96
98
  m << v.prefix
97
99
  end
98
100
  warn "#{code} does not have a recognised prefix: #{allowed.join(', ')}"
99
- nil
100
101
  end
101
102
 
102
103
  # TODO: i18n
@@ -105,7 +106,7 @@ module Relaton
105
106
  # @param year [String]
106
107
  # @param opts [Hash]
107
108
  # @param stdClass [Symbol]
108
- # @return [Array]
109
+ # @return [Array<String>] docid and code
109
110
  def std_id(code, year, opts, stdclass)
110
111
  prefix, code = strip_id_wrapper(code, stdclass)
111
112
  ret = code
@@ -126,10 +127,11 @@ module Relaton
126
127
 
127
128
  # @param entry [String] XML string
128
129
  # @param stdclass [Symbol]
130
+ # @param id [String] docid
129
131
  # @return [NilClass, RelatonIsoBib::IsoBibliographicItem,
130
132
  # RelatonItu::ItuBibliographicItem, RelatonIetf::IetfBibliographicItem,
131
133
  # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem]
132
- def bib_retval(entry, stdclass)
134
+ def bib_retval(entry, stdclass, id)
133
135
  entry =~ /^not_found/ ? nil : @registry.processors[stdclass].from_xml(entry)
134
136
  end
135
137
 
@@ -142,39 +144,51 @@ module Relaton
142
144
  # RelatonNist::NistBibliongraphicItem, RelatonGb::GbbibliographicItem]
143
145
  def check_bibliocache(code, year, opts, stdclass)
144
146
  id, searchcode = std_id(code, year, opts, stdclass)
147
+ yaml = @static_db[id]
148
+ return @registry.processors[stdclass].hash_to_bib YAML.safe_load(yaml) if yaml
149
+
145
150
  db = @local_db || @db
146
151
  altdb = @local_db && @db ? @db : nil
147
- return bib_retval(new_bib_entry(searchcode, year, opts, stdclass), stdclass) if db.nil?
152
+ bibentry = new_bib_entry(searchcode, year, opts, stdclass, db: db, id: id)
153
+ return bib_retval(bibentry, stdclass, id) if db.nil?
148
154
 
149
155
  db.delete(id) unless db.valid_entry?(id, year)
150
156
  if altdb
151
157
  # db[id] ||= altdb[id]
152
158
  db.clone_entry id, altdb
153
- db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db, id)
159
+ db[id] ||= bibentry
154
160
  altdb.clone_entry(id, db) if !altdb.valid_entry?(id, year)
155
161
  else
156
- db[id] ||= new_bib_entry(searchcode, year, opts, stdclass, db, id)
162
+ db[id] ||= bibentry
157
163
  end
158
- bib_retval(db[id], stdclass)
164
+ bib_retval(db[id], stdclass, id)
159
165
  end
160
166
 
161
167
  # @param code [String]
162
168
  # @param year [String]
163
169
  # @param opts [Hash]
164
170
  # @param stdclass [Symbol]
171
+ # @param db [Relaton::DbCache,`NilClass]
172
+ # @param id [String] docid
165
173
  # @return [String]
166
- def new_bib_entry(code, year, opts, stdclass, db = nil, id = nil)
174
+ def new_bib_entry(code, year, opts, stdclass, **args)
167
175
  bib = @registry.processors[stdclass].get(code, year, opts)
168
176
  bib_id = bib&.docidentifier&.first&.id&.sub(%r{(?<=\d)-(?=\d{4})}, ":")
169
- if db && id && bib_id && id !~ %r{\(#{bib_id}\)}
177
+
178
+ # when docid doesn't match bib's id then return a reference to bib's id
179
+ if args[:db] && args[:id] && bib_id && args[:id] !~ %r{\(#{bib_id}\)}
170
180
  bid = std_id(bib.docidentifier.first.id, nil, {}, stdclass).first
171
- db[bid] ||= bib_entry bib
181
+ args[:db][bid] ||= bib_entry bib
172
182
  "redirection #{bid}"
173
183
  else
174
184
  bib_entry bib
175
185
  end
176
186
  end
177
187
 
188
+ # @param bib [RelatonGb::GbBibliongraphicItem, RelatonIsoBib::IsoBibliographicItem,
189
+ # RelatonIetf::IetfBibliographicItem, RelatonItu::ItuBibliographicItem,
190
+ # RelatonNist::NistBibliongraphicItem, RelatonOgc::OgcBibliographicItem]
191
+ # @return [String] XML or "not_found mm-dd-yyyy"
178
192
  def bib_entry(bib)
179
193
  if bib.respond_to? :to_xml
180
194
  bib.to_xml(bibdata: true)
@@ -184,22 +198,21 @@ module Relaton
184
198
  end
185
199
 
186
200
  # @param dir [String] DB directory
187
- # @param global [TrueClass, FalseClass]
188
- # @return [PStore]
189
- def open_cache_biblio(dir, global: true)
201
+ # @param type [Symbol]
202
+ # @return [Relaton::DbCache, NilClass]
203
+ def open_cache_biblio(dir, type: :static)
190
204
  return nil if dir.nil?
191
205
 
192
- db = DbCache.new dir
193
- if global
194
- unless db.check_version?
195
- FileUtils.rm_rf(Dir.glob(dir + "/*"), secure: true)
196
- warn "Global cache version is obsolete and cleared."
197
- end
206
+ db = DbCache.new dir, type == :static ? "yml" : "xml"
207
+ return db if db.check_version?
208
+
209
+ case type
210
+ when :global
211
+ FileUtils.rm_rf(Dir.glob(dir + "/*"), secure: true)
212
+ warn "Global cache version is obsolete and cleared."
198
213
  db.set_version
199
- elsif db.check_version? then db
200
- else
201
- warn "Local cache version is obsolete."
202
- nil
214
+ when :static then warn "Static cache version is obsolete."
215
+ else warn "Local cache version is obsolete."
203
216
  end
204
217
  end
205
218
  end
@@ -6,8 +6,9 @@ module Relaton
6
6
  attr_reader :dir
7
7
 
8
8
  # @param dir [String] DB directory
9
- def initialize(dir)
9
+ def initialize(dir, ext = "xml")
10
10
  @dir = dir
11
+ @ext = ext
11
12
  FileUtils::mkdir_p @dir
12
13
  file_version = "#{@dir}/version"
13
14
  set_version unless File.exist? file_version
@@ -80,7 +81,7 @@ module Relaton
80
81
  # @return [TrueClass, FalseClass]
81
82
  def check_version?
82
83
  v = File.read @dir + "/version", encoding: "utf-8"
83
- v == VERSION
84
+ v.strip == VERSION
84
85
  end
85
86
 
86
87
  # Set version of the DB to the gem version.
@@ -131,11 +132,11 @@ module Relaton
131
132
  def filename(key)
132
133
  prefcode = key.downcase.match /^(?<prefix>[^\(]+)\((?<code>[^\)]+)/
133
134
  fn = if prefcode
134
- "#{@dir}/#{prefcode[:prefix]}/#{prefcode[:code].gsub(/[-:\s\/]/, '_')}"
135
+ "#{prefcode[:prefix]}/#{prefcode[:code].gsub(/[-:\s\/]/, '_')}"
135
136
  else
136
- "#{@dir}/#{key.gsub(/[-:\s]/, '_')}"
137
+ key.gsub(/[-:\s]/, "_")
137
138
  end
138
- fn.sub(/_$/, "") + ".xml"
139
+ "#{@dir}/#{fn.sub(/(,|_$)/, '')}.#{@ext}"
139
140
  end
140
141
 
141
142
  # Return item's subdir
@@ -46,7 +46,7 @@ module Relaton
46
46
  processors[short.to_sym]
47
47
  end
48
48
 
49
- # @return [Array]
49
+ # @return [Array<Symbol>]
50
50
  def supported_processors
51
51
  processors.keys
52
52
  end
@@ -0,0 +1,33 @@
1
+ title:
2
+ - type: title-main
3
+ content: Procedures for the technical work
4
+ language: en
5
+ script: Latn
6
+
7
+ link:
8
+ - type: obp
9
+ content: https://www.iec.ch/members_experts/refdocs/iec/isoiecdir1%7Bed15.0%7Den.pdf
10
+
11
+ type: international-standard
12
+
13
+ docid:
14
+ id: ISO/IEC DIR 1
15
+ type: ISO
16
+
17
+ date:
18
+ type: published
19
+ value: '2019-05-01'
20
+
21
+ edition: "15"
22
+
23
+ language:
24
+ - en
25
+
26
+ script: Latn
27
+
28
+ copyright:
29
+ owner:
30
+ name: International Electrotechnical Commission
31
+ abbreviation: IEC
32
+ url: iec.ch
33
+ from: '2019'
@@ -0,0 +1,32 @@
1
+ title:
2
+ - type: title-main
3
+ content: Procedures for the technical work – Procedures specific to IEC
4
+ language: en
5
+ script: Latn
6
+
7
+ link:
8
+ - type: obp
9
+ content: https://www.iec.ch/members_experts/refdocs/iec/isoiecdir1-consolidatediecsup%7bed15.0.RLV%7den.pdf
10
+
11
+ type: international-standard
12
+
13
+ docid:
14
+ id: ISO/IEC DIR 1 IEC SUP
15
+ type: ISO
16
+
17
+ date:
18
+ type: published
19
+ value: '2019-05-01'
20
+
21
+ edition: "15"
22
+
23
+ language: en
24
+
25
+ script: Latn
26
+
27
+ copyright:
28
+ owner:
29
+ name: International Electrotechnical Commission
30
+ abbreviation: IEC
31
+ url: iec.ch
32
+ from: '2019'
@@ -0,0 +1,39 @@
1
+ title:
2
+ - type: title-main
3
+ content: Consolidated ISO Supplement -- Procedures specific to ISO
4
+ language: en
5
+ script: Latn
6
+ - type: title-main
7
+ content: Supplément ISO consolidé — Procédures spécifiques à l’ISO
8
+ language: fr
9
+ script: Latn
10
+
11
+ link:
12
+ - type: src
13
+ content: https://www.iso.org/sites/directives/current/consolidated/index.xhtml
14
+ - type: obp
15
+ content: https://isotc.iso.org/livelink/livelink/fetch/2000/2122/4230450/4230452/ISO_IEC_Directives_Part_1_and_Consolidated_ISO_Supplement_%2D_2019_%2810th_Edition%29_%2D_PDF.pdf?nodeid=20447676&vernum=-2
16
+
17
+ type: international-standard
18
+
19
+ docid:
20
+ id: ISO/IEC DIR 1 ISO SUP
21
+ type: ISO
22
+
23
+ date:
24
+ type: published
25
+ value: '2019-01-01'
26
+
27
+ edition: "10"
28
+
29
+ language:
30
+ - en
31
+
32
+ script: Latn
33
+
34
+ copyright:
35
+ owner:
36
+ name: International Organization for Standardization
37
+ abbreviation: ISO
38
+ url: www.iso.org
39
+ from: '2019'
@@ -0,0 +1,32 @@
1
+ title:
2
+ - type: title-main
3
+ content: Principles and rules for the structure and drafting of ISO and IEC documents
4
+ language: en
5
+ script: Latn
6
+
7
+ link:
8
+ - type: obp
9
+ content: https://www.iec.ch/members_experts/refdocs/iec/isoiecdir2%7Bed8.0.RLV%7Den.pdf
10
+
11
+ type: international-standard
12
+
13
+ docid:
14
+ id: ISO/IEC DIR 2 IEC
15
+ type: ISO
16
+
17
+ date:
18
+ type: published
19
+ value: '2018-05-01'
20
+
21
+ edition: "8"
22
+
23
+ language: en
24
+
25
+ script: Latn
26
+
27
+ copyright:
28
+ owner:
29
+ name: International Electrotechnical Commission
30
+ abbreviation: IEC
31
+ url: iec.ch
32
+ from: '2019'
@@ -0,0 +1,39 @@
1
+ title:
2
+ - type: title-main
3
+ content: Principles and rules for the structure and drafting of ISO and IEC documents
4
+ language: en
5
+ script: Latn
6
+ - type: title-main
7
+ content: Principes et règles de structure et de rédaction des documents
8
+ language: fr
9
+ script: Latn
10
+
11
+ link:
12
+ - type: src
13
+ content: https://www.iso.org/sites/directives/current/part2/index.xhtml
14
+ - type: obp
15
+ content: https://isotc.iso.org/livelink/livelink/fetch/2000/2122/4230450/4230456/ISO_IEC_Directives%2C_Part_2%2C_Principles_and_rules_for_the_structure_and_drafting_of_ISO_and_IEC_documents_-_2018_%288th_edition%29_-_PDF.pdf?nodeid=19685788&vernum=-2
16
+
17
+ type: international-standard
18
+
19
+ docid:
20
+ id: ISO/IEC DIR 2 ISO
21
+ type: ISO
22
+
23
+ date:
24
+ type: published
25
+ value: '2018-01-01'
26
+
27
+ edition: "8"
28
+
29
+ language:
30
+ - en
31
+
32
+ script: Latn
33
+
34
+ copyright:
35
+ owner:
36
+ name: International Organization for Standardization
37
+ abbreviation: ISO
38
+ url: www.iso.org
39
+ from: '2019'
@@ -0,0 +1,32 @@
1
+ title:
2
+ - type: title-main
3
+ content: Procedures specific to IEC
4
+ language: en
5
+ script: Latn
6
+
7
+ link:
8
+ - type: obp
9
+ content: https://www.iec.ch/members_experts/refdocs/iec/isoiecdir1-iecsup%7bed13.0%7den.pdf
10
+
11
+ type: international-standard
12
+
13
+ docid:
14
+ id: ISO/IEC DIR IEC SUP
15
+ type: ISO
16
+
17
+ date:
18
+ type: published
19
+ value: '2019-05-01'
20
+
21
+ edition: "13"
22
+
23
+ language: en
24
+
25
+ script: Latn
26
+
27
+ copyright:
28
+ owner:
29
+ name: International Electrotechnical Commission
30
+ abbreviation: IEC
31
+ url: iec.ch
32
+ from: '2019'
@@ -0,0 +1,32 @@
1
+ title:
2
+ - type: title-main
3
+ content: Procedures specific to JTC 1
4
+ language: en
5
+ script: Latn
6
+
7
+ link:
8
+ - type: obp
9
+ content: https://www.iec.ch/members_experts/refdocs/iec/Consolidated_JTC_1_Supplement_2018.pdf
10
+
11
+ type: international-standard
12
+
13
+ docid:
14
+ id: ISO/IEC DIR JTC 1 SUP
15
+ type: ISO
16
+
17
+ date:
18
+ type: published
19
+ value: '2018-05-01'
20
+
21
+ edition: "14"
22
+
23
+ language: en
24
+
25
+ script: Latn
26
+
27
+ copyright:
28
+ owner:
29
+ name: International Electrotechnical Commission
30
+ abbreviation: IEC
31
+ url: iec.ch
32
+ from: '2019'
@@ -0,0 +1 @@
1
+ 0.5.6
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "0.5.5".freeze
2
+ VERSION = "0.5.6".freeze
3
3
  end
@@ -1 +1 @@
1
- 0.5.5
1
+ 0.5.6
@@ -1,6 +1,3 @@
1
- require "spec_helper"
2
- require "fileutils"
3
-
4
1
  RSpec.describe Relaton::DbCache do
5
2
  it "creates default caches" do
6
3
  FileUtils.mv File.expand_path("~/.relaton"), "relaton1", force: true
@@ -1,16 +1,70 @@
1
1
  RSpec.describe Relaton::Db do
2
+ before(:each) { FileUtils.rm_rf %w[testcache testcache2] }
3
+
2
4
  it "returns docid type" do
3
- FileUtils.rm_rf %w(testcache testcache2)
4
5
  db = Relaton::Db.new "testcache", "testcache2"
5
6
  expect(db.docid_type("CN(GB/T 1.1)")).to eq ["Chinese Standard", "GB/T 1.1"]
6
7
  end
7
8
 
8
9
  it "fetch when no local db" do
9
- FileUtils.rm_rf %w(testcache testcache2)
10
10
  db = Relaton::Db.new "testcache", nil
11
11
  VCR.use_cassette "iso_19115_1" do
12
12
  bib = db.fetch("ISO 19115-1", nil, {})
13
13
  expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
14
14
  end
15
15
  end
16
+
17
+ it "fetch std" do
18
+ db = Relaton::Db.new "testcache", nil
19
+ VCR.use_cassette "iso_19115_1" do
20
+ bib = db.fetch_std("ISO 19115-1", nil, :relaton_iso, {})
21
+ expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
22
+ end
23
+ end
24
+
25
+ context "fetch documents form static cache" do
26
+ let(:db) { db = Relaton::Db.new nil, nil }
27
+
28
+ it "fetches ISO/IEC DIR 1 IEC SUP" do
29
+ bib = db.fetch "ISO/IEC DIR 1 IEC SUP"
30
+ expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
31
+ expect(bib.docidentifier.first.id).to eq "ISO/IEC DIR 1 IEC SUP"
32
+ end
33
+
34
+ it "fetches ISO/IEC DIR 1 ISO SUP" do
35
+ bib = db.fetch "ISO/IEC DIR 1 ISO SUP"
36
+ expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
37
+ expect(bib.docidentifier.first.id).to eq "ISO/IEC DIR 1 ISO SUP"
38
+ end
39
+
40
+ it "fetches ISO/IEC DIR 1" do
41
+ bib = db.fetch "ISO/IEC DIR 1"
42
+ expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
43
+ expect(bib.docidentifier.first.id).to eq "ISO/IEC DIR 1"
44
+ end
45
+
46
+ it "fetches ISO/IEC DIR 2 IEC" do
47
+ bib = db.fetch "ISO/IEC DIR 2 IEC"
48
+ expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
49
+ expect(bib.docidentifier.first.id).to eq "ISO/IEC DIR 2 IEC"
50
+ end
51
+
52
+ it "fetches ISO/IEC DIR 2 ISO" do
53
+ bib = db.fetch "ISO/IEC DIR 2 ISO"
54
+ expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
55
+ expect(bib.docidentifier.first.id).to eq "ISO/IEC DIR 2 ISO"
56
+ end
57
+
58
+ it "fetches ISO/IEC DIR IEC SUP" do
59
+ bib = db.fetch "ISO/IEC DIR IEC SUP"
60
+ expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
61
+ expect(bib.docidentifier.first.id).to eq "ISO/IEC DIR IEC SUP"
62
+ end
63
+
64
+ it "fetches ISO/IEC DIR JTC 1 SUP" do
65
+ bib = db.fetch "ISO/IEC DIR JTC 1 SUP"
66
+ expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
67
+ expect(bib.docidentifier.first.id).to eq "ISO/IEC DIR JTC 1 SUP"
68
+ end
69
+ end
16
70
  end
@@ -0,0 +1,27 @@
1
+ module Relaton
2
+ class TestProcessor < Relaton::Processor
3
+ def initialize; end
4
+ end
5
+ end
6
+
7
+ RSpec.describe Relaton::Processor do
8
+ it "initialize should be implemented" do
9
+ expect { Relaton::Processor.new }.to raise_error StandardError
10
+ end
11
+
12
+ context "instance of processor" do
13
+ subject { Relaton::TestProcessor.new }
14
+
15
+ it "get method should be implemented" do
16
+ expect { subject.get "code", nil, {} }.to raise_error StandardError
17
+ end
18
+
19
+ it "from_xml method should be implemented" do
20
+ expect { subject.from_xml "" }.to raise_error StandardError
21
+ end
22
+
23
+ it "hash_to_bib method should be implemented" do
24
+ expect { subject.hash_to_bib({}) }.to raise_error StandardError
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,21 @@
1
+ RSpec.describe Relaton::Registry do
2
+ it "outputs backend not present" do
3
+ stub_const "Relaton::Registry::SUPPORTED_GEMS", ["not_supported_gem"]
4
+ expect { Relaton::Registry.clone.instance }.to output(
5
+ /backend not_supported_gem not present/,
6
+ ).to_stdout
7
+ end
8
+
9
+ it "finds processor" do
10
+ expect(Relaton::Registry.instance.find_processor("relaton_iso")).
11
+ to be_instance_of RelatonIso::Processor
12
+ end
13
+
14
+ it "returns supported processors" do
15
+ expect(Relaton::Registry.instance.supported_processors).to include :relaton_iso
16
+ end
17
+
18
+ it "finds processor by type" do
19
+ expect(Relaton::Registry.instance.by_type("ISO")).to be_instance_of RelatonIso::Processor
20
+ end
21
+ end
@@ -1,6 +1,3 @@
1
- require "spec_helper"
2
- require "fileutils"
3
-
4
1
  RSpec.describe Relaton::Db do
5
2
  # let!(:db) { Relaton::Db.new("testcache", "testcache2") }
6
3
 
@@ -32,7 +29,7 @@ RSpec.describe Relaton::Db do
32
29
  VCR.use_cassette "19133_2005" do
33
30
  bib = @db.fetch("ISO 19133:2005")
34
31
  expect(bib).to be_instance_of RelatonIsoBib::IsoBibliographicItem
35
- expect(bib.to_xml).to include "<bibitem id=\"ISO19133-2005\" type=\"standard\">"
32
+ expect(bib.to_xml).to include '<bibitem id="ISO19133-2005" type="standard">'
36
33
  testcache = Relaton::DbCache.new "testcache"
37
34
  expect(testcache.valid_entry?("ISO(ISO 19133:2005)", "2019")).to eq Date.today.year.to_s
38
35
  end
@@ -150,29 +147,4 @@ RSpec.describe Relaton::Db do
150
147
  testcache = db.instance_variable_get :@local_db
151
148
  expect(testcache).to be_nil
152
149
  end
153
-
154
- private
155
-
156
- # @param count [Integer] number of stubbing
157
- def stub_bib(bib_type, count = 1)
158
- expect(bib_type).to receive(:get).and_wrap_original do |m, *args|
159
- get_resp m, *args
160
- end.exactly(count).times
161
- end
162
-
163
- def get_resp(method, *args)
164
- expect_args args
165
- file = "spec/support/" + args[0].downcase.gsub(/[\/\s-]/, "_")
166
- file += "_#{args[1]}" if args[1]
167
- file += ".xml"
168
- File.write file, method.call(*args)&.to_xml, encoding: "utf-8" unless File.exist? file
169
- File.read file, encoding: "utf-8"
170
- end
171
-
172
- def expect_args(args)
173
- expect(args.size).to eq 3
174
- expect(args[0]).to be_instance_of String
175
- expect(args[1]).to be_instance_of(NilClass).or be_instance_of String
176
- expect(args[2]).to be_instance_of Hash
177
- end
178
150
  end
@@ -12,6 +12,7 @@ SimpleCov.start do
12
12
  add_filter "/spec/"
13
13
  end
14
14
 
15
+ require "fileutils"
15
16
  require "bundler/setup"
16
17
  require "relaton"
17
18
  require "rspec/matchers"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.5
4
+ version: 0.5.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-09-27 00:00:00.000000000 Z
11
+ date: 2019-10-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: relaton-gb
@@ -332,6 +332,7 @@ extra_rdoc_files: []
332
332
  files:
333
333
  - ".gitignore"
334
334
  - ".hound.yml"
335
+ - ".rspec"
335
336
  - ".rubocop.yml"
336
337
  - ".travis.yml"
337
338
  - Gemfile
@@ -349,12 +350,22 @@ files:
349
350
  - lib/relaton/db_cache.rb
350
351
  - lib/relaton/processor.rb
351
352
  - lib/relaton/registry.rb
353
+ - lib/relaton/static_cache/iso/iso_iec_dir_1.yml
354
+ - lib/relaton/static_cache/iso/iso_iec_dir_1_iec_sup.yml
355
+ - lib/relaton/static_cache/iso/iso_iec_dir_1_iso_sup.yml
356
+ - lib/relaton/static_cache/iso/iso_iec_dir_2_iec.yml
357
+ - lib/relaton/static_cache/iso/iso_iec_dir_2_iso.yml
358
+ - lib/relaton/static_cache/iso/iso_iec_dir_iec_sup.yml
359
+ - lib/relaton/static_cache/iso/iso_iec_dir_jtc_1_sup.yml
360
+ - lib/relaton/static_cache/version
352
361
  - lib/relaton/version.rb
353
362
  - relaton.gemspec
354
363
  - relaton/cache/version
355
364
  - spec/relaton/db_cache_spec.rb
356
365
  - spec/relaton/db_spec.rb
357
- - spec/relaton/relaton_spec.rb
366
+ - spec/relaton/processor_spec.rb
367
+ - spec/relaton/regirtry_spec.rb
368
+ - spec/relaton_spec.rb
358
369
  - spec/spec_helper.rb
359
370
  - spec/support/gb_t_20223_2006.xml
360
371
  - spec/support/iso_111111119115_1.xml