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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e446497655bcb343d4bb1846cee85481c1f239fb8b2669b0f960f6f5ef539bf8
4
- data.tar.gz: 7ff5bdf7f8e567a0b02be1250ce2c0789e9343275670104ed1df7794e85b0587
3
+ metadata.gz: 1c97ee373e8454f0e9bc2050074e3a291dd19af6eb7e4caf82b4fdf7f1a81f85
4
+ data.tar.gz: c295361c298708f5cc21155d15b5f7c96e7526f46e1986d0c7d5dea8ef466ddb
5
5
  SHA512:
6
- metadata.gz: 2a7951825e48b973a89ff2ebd231b375f210ab18c0cb1e453551241ca45055d0015759f8422f3a72316ed1ab6531df9ae705f29ee7ad9ed97fff3f908bd75042
7
- data.tar.gz: 666fc454ae89e31ca71423a478f75960e24258a15e2e42ba51841402e24e2f04c13551fbbe1f231d63b9d642f2c08ff74fdba4ffc204f51d2895ae4dfcfe50db
6
+ metadata.gz: 2dc0a45b6022acc12df6026babdf0a3e1aadc1af73a08238afce32a4b4053f7db36290cfcc1edd14aa1ef5401fb3b9f16e71e25c931944afd549a5b5cc19f414
7
+ data.tar.gz: e9b37a99f8269b7bcf48be11c5ac2cd6955c00fa32d2b21416fbd60f377473c93b47e26d3af96a62e45e9d3fecf4ff873953fe91ecfdeffd584f94ca7a6413a1
@@ -1,4 +1,4 @@
1
- require_relative "relaton/relaton"
1
+ require_relative "relaton/db"
2
2
  require_relative "relaton/version"
3
3
  require_relative "relaton/registry"
4
4
  require_relative "relaton/processor"
@@ -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
- require b
25
- rescue LoadError
26
- puts "[relaton] backend #{b} not present"
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
- raise(RelatonError,
58
- "#{code} does not have a recognised prefix: "\
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
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "0.0.1".freeze
2
+ VERSION = "0.0.2".freeze
3
3
  end
@@ -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 raise_error(Relaton::RelatonError)
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.1
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-07 00:00:00.000000000 Z
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