relaton 0.0.1 → 0.0.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 +4 -4
- data/lib/relaton.rb +1 -1
- data/lib/relaton/{relaton.rb → db.rb} +11 -10
- data/lib/relaton/version.rb +1 -1
- data/spec/relaton/relaton_spec.rb +17 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c97ee373e8454f0e9bc2050074e3a291dd19af6eb7e4caf82b4fdf7f1a81f85
|
4
|
+
data.tar.gz: c295361c298708f5cc21155d15b5f7c96e7526f46e1986d0c7d5dea8ef466ddb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2dc0a45b6022acc12df6026babdf0a3e1aadc1af73a08238afce32a4b4053f7db36290cfcc1edd14aa1ef5401fb3b9f16e71e25c931944afd549a5b5cc19f414
|
7
|
+
data.tar.gz: e9b37a99f8269b7bcf48be11c5ac2cd6955c00fa32d2b21416fbd60f377473c93b47e26d3af96a62e45e9d3fecf4ff873953fe91ecfdeffd584f94ca7a6413a1
|
data/lib/relaton.rb
CHANGED
@@ -4,8 +4,6 @@ module Relaton
|
|
4
4
|
class RelatonError < StandardError; end
|
5
5
|
|
6
6
|
class Db
|
7
|
-
#PREFIXES = ["GB Standard", "IETF", "ISO", "IEC", "IEV"]
|
8
|
-
|
9
7
|
SUPPORTED_GEMS = %w[ isobib rfcbib gbbib ].freeze
|
10
8
|
|
11
9
|
def initialize(global_cache, local_cache)
|
@@ -21,9 +19,11 @@ module Relaton
|
|
21
19
|
puts "[relaton] detecting backends:"
|
22
20
|
SUPPORTED_GEMS.each do |b|
|
23
21
|
puts b
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
begin
|
23
|
+
require b
|
24
|
+
rescue LoadError
|
25
|
+
puts "[relaton] backend #{b} not present"
|
26
|
+
end
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -34,11 +34,11 @@ module Relaton
|
|
34
34
|
# @param opts [Hash] options; restricted to :all_parts if all-parts reference is required
|
35
35
|
# @return [String] Relaton XML serialisation of reference
|
36
36
|
def fetch(code, year = nil, opts = {})
|
37
|
-
stdclass = standard_class(code)
|
37
|
+
stdclass = standard_class(code) or return nil
|
38
38
|
check_bibliocache(code, year, opts, stdclass)
|
39
39
|
end
|
40
40
|
|
41
|
-
def save
|
41
|
+
def save
|
42
42
|
save_cache_biblio(@bibdb, @bibdb_name)
|
43
43
|
save_cache_biblio(@local_bibdb, @local_bibdb_name)
|
44
44
|
end
|
@@ -54,12 +54,12 @@ module Relaton
|
|
54
54
|
@registry.processors.each do |name, processor|
|
55
55
|
processor.prefix.match? code and return name
|
56
56
|
end
|
57
|
-
|
58
|
-
|
59
|
-
"#{@registry.supported_processors.join(', ')}")
|
57
|
+
warn "#{code} does not have a recognised prefix: "\
|
58
|
+
"#{@registry.processors.inject([]) { |m, (k, v)| m << v.prefix.inspect }.join(', ')}"
|
60
59
|
nil
|
61
60
|
end
|
62
61
|
|
62
|
+
# TODO: i18n
|
63
63
|
def std_id(code, year, opts, _stdclass)
|
64
64
|
ret = code
|
65
65
|
ret += ":#{year}" if year
|
@@ -74,6 +74,7 @@ module Relaton
|
|
74
74
|
@bibdb[id] ||= new_bibcache_entry(code, year, opts, stdclass)
|
75
75
|
@local_bibdb[id] = @bibdb[id] if !@local_bibdb.nil? &&
|
76
76
|
!is_valid_bibcache_entry?(@local_bibdb[id], year)
|
77
|
+
return nil if @bibdb[id].nil?
|
77
78
|
return @local_bibdb[id]["bib"] unless @local_bibdb.nil?
|
78
79
|
@bibdb[id]["bib"]
|
79
80
|
end
|
data/lib/relaton/version.rb
CHANGED
@@ -4,7 +4,7 @@ RSpec.describe Relaton::Db do
|
|
4
4
|
it "rejects an illegal reference prefix" do
|
5
5
|
system "rm testcache.json testcache2.json"
|
6
6
|
db = Relaton::Db.new("testcache.json", "testcache2.json")
|
7
|
-
expect{db.fetch("XYZ XYZ", nil, {})}.to
|
7
|
+
expect{db.fetch("XYZ XYZ", nil, {})}.to output(/does not have a recognised prefix/).to_stderr
|
8
8
|
db.save()
|
9
9
|
expect(File.exist?("testcache.json")).to be true
|
10
10
|
expect(File.exist?("testcache2.json")).to be true
|
@@ -30,6 +30,22 @@ RSpec.describe Relaton::Db do
|
|
30
30
|
expect(testcache).to include "<bibitem type=\\\"international-standard\\\" id=\\\"ISO19115-1\\\">"
|
31
31
|
end
|
32
32
|
|
33
|
+
it "deals with a non-existant ISO reference" do
|
34
|
+
mock_algolia 2
|
35
|
+
system "rm testcache.json testcache2.json"
|
36
|
+
db = Relaton::Db.new("testcache.json", "testcache2.json")
|
37
|
+
bib = db.fetch("ISO 111111119115-1", nil, {})
|
38
|
+
expect(bib).to be_nil
|
39
|
+
db.save()
|
40
|
+
expect(File.exist?("testcache.json")).to be true
|
41
|
+
expect(File.exist?("testcache2.json")).to be true
|
42
|
+
testcache = File.read "testcache.json"
|
43
|
+
expect(testcache).to include %("ISO 111111119115-1":null)
|
44
|
+
testcache = File.read "testcache2.json"
|
45
|
+
expect(testcache).to include %("ISO 111111119115-1":null)
|
46
|
+
end
|
47
|
+
|
48
|
+
|
33
49
|
private
|
34
50
|
|
35
51
|
# rubocop:disable Naming/UncommunicativeBlockParamName, Naming/VariableName
|
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.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: asciidoctor
|
@@ -269,9 +269,9 @@ files:
|
|
269
269
|
- README.adoc
|
270
270
|
- bin/rspec
|
271
271
|
- lib/relaton.rb
|
272
|
+
- lib/relaton/db.rb
|
272
273
|
- lib/relaton/processor.rb
|
273
274
|
- lib/relaton/registry.rb
|
274
|
-
- lib/relaton/relaton.rb
|
275
275
|
- lib/relaton/version.rb
|
276
276
|
- relaton.gemspec
|
277
277
|
- spec/relaton/relaton_spec.rb
|