relaton 0.1.0 → 0.1.1

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
  SHA256:
3
- metadata.gz: bec19dd26e20ad03b8e537bbfcaab9f5cf75dc005ab71d83a094c99b80f08aaa
4
- data.tar.gz: 161b82000e567929a9a3faa39669acbfd4528dd6c1ff6dab6610314248b85553
3
+ metadata.gz: bdc3737ec5342a53ecbfe76300389b0afb81b32bd6c7aaa45ccbf450f679d886
4
+ data.tar.gz: 596df09db41419e1aa452d6a0dee24556c4a6b885c121c31b7b3426c42233297
5
5
  SHA512:
6
- metadata.gz: c56f8d929682c8bde40d0b559cb3f5879107dd9bae7032551dbe6a6923555cc5c8107411f73db57d7150b35f8fa8cd9cb807a67b4a170ef855921fbf07ba8e21
7
- data.tar.gz: 51c4e74ee9e8610b1bd49d972bbcda8e210355f949be4f264af8beb632fe7eb5fc27ed2dcbbd15201e38c5a91f107e6957e9c6fbfc380ba5728fe3469bd7ac35
6
+ metadata.gz: 1511495c2d16d1364682f7d5cb0f0d3e61bab30e97611b5fefa563ee7cd7653a205f0b1405293c95a4212e67c42aeb528211302560a123d4ee38be6170423f92
7
+ data.tar.gz: 5ed4ef760452c3e1bc60644ae773548e5d8683b29663bc0ded1a9cc77e227a9c556c3bfe289ced91dc836c3d60259984dd671a788f1d72c9caa8689fd36ee744
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- relaton (0.0.2)
4
+ relaton (0.1.1)
5
5
  algoliasearch
6
6
  gbbib (~> 0.1.0)
7
7
  iev (~> 0.1.0)
@@ -44,7 +44,7 @@ GEM
44
44
  httpclient (2.8.3)
45
45
  iev (0.1.0)
46
46
  nokogiri
47
- iso-bib-item (0.2.0)
47
+ iso-bib-item (0.2.1)
48
48
  isoics (~> 0.1.6)
49
49
  nokogiri (~> 1.8.4)
50
50
  ruby_deep_clone (~> 0.8.0)
@@ -44,8 +44,10 @@ module Relaton
44
44
  # @param key [String]
45
45
  # @return [Hash]
46
46
  def load_entry(key)
47
- entry = @local_db.transaction { @local_db[key] }
48
- return entry if entry
47
+ unless @local_db.nil?
48
+ entry = @local_db.transaction { @local_db[key] }
49
+ return entry if entry
50
+ end
49
51
  @db.transaction { @db[key] }
50
52
  end
51
53
 
@@ -54,12 +56,13 @@ module Relaton
54
56
  # @option value [Date] "fetched"
55
57
  # @option value [IsoBibItem::IsoBibliographicItem] "bib"
56
58
  def save_entry(key, value)
57
- @db.transaction { @db[key] = value }
58
- @local_db.transaction { @local_db[key] = value }
59
+ @db.nil? or @db.transaction { @db[key] = value }
60
+ @local_db.nil? or @local_db.transaction { @local_db[key] = value }
59
61
  end
60
62
 
61
63
  # list all entris as a serialization
62
64
  def to_xml
65
+ return nil if @db.nil?
63
66
  @db.transaction do
64
67
  Nokogiri::XML::Builder.new(encoding: "UTF-8") do |xml|
65
68
  xml.documents do
@@ -100,19 +103,26 @@ module Relaton
100
103
  ret
101
104
  end
102
105
 
106
+ def bib_retval(entry)
107
+ entry["bib"] == "not_found" ? nil : entry["bib"]
108
+ end
109
+
103
110
  # @param code [String]
104
111
  # @param year [String]
105
112
  # @param opts [Hash]
106
113
  # @param stdclass [Symbol]
107
114
  def check_bibliocache(code, year, opts, stdclass)
108
115
  id = std_id(code, year, opts, stdclass)
109
- return nil if @db.nil? # signals we will not be using isobib
116
+ return bib_retval(new_bib_entry(code, year, opts, stdclass)) if @db.nil?
110
117
  @db.transaction do
111
118
  @db.delete(id) unless valid_bib_entry?(@db[id], year)
112
119
  @db[id] ||= new_bib_entry(code, year, opts, stdclass)
113
- @local_db.transaction do
114
- @local_db[id] = @db[id] if !valid_bib_entry?(@local_db[id], year)
115
- @local_db[id]["bib"] == "not_found" ? nil : @local_db[id]["bib"]
120
+ if @local_db.nil? then bib_retval(@db[id])
121
+ else
122
+ @local_db.transaction do
123
+ @local_db[id] = @db[id] if !valid_bib_entry?(@local_db[id], year)
124
+ bib_retval(@local_db[id])
125
+ end
116
126
  end
117
127
  end
118
128
  end
@@ -134,12 +144,13 @@ module Relaton
134
144
  # @param year [String]
135
145
  def valid_bib_entry?(bib, year)
136
146
  bib&.is_a?(Hash) && bib&.has_key?("bib") && bib&.has_key?("fetched") &&
137
- (year || Date.today - bib["fetched"] < 60)
147
+ (year || Date.today - Date.iso8601(bib["fetched"]) < 60)
138
148
  end
139
149
 
140
150
  # @param filename [String] DB filename
141
151
  # @return [Hash]
142
152
  def open_cache_biblio(filename)
153
+ return nil if filename.nil?
143
154
  PStore.new filename
144
155
  # biblio = {}
145
156
  # return {} unless !filename.nil? && Pathname.new(filename).file?
@@ -1,3 +1,3 @@
1
1
  module Relaton
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "0.1.1".freeze
3
3
  end
@@ -22,7 +22,7 @@ RSpec.describe Relaton::Db do
22
22
  system "rm testcache testcache2"
23
23
  db = Relaton::Db.new("testcache", "testcache2")
24
24
  bib = db.fetch("ISO 19115-1", nil, {})
25
- db.fetch("ISO 19115-1", nil, {})
25
+ #db.fetch("ISO 19115-1", nil, {})
26
26
  expect(bib).to be_instance_of IsoBibItem::IsoBibliographicItem
27
27
  expect(bib.to_xml).to include "<bibitem type=\"international-standard\" id=\"ISO19115-1\">"
28
28
  expect(File.exist?("testcache")).to be true
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: relaton
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.