relaton 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.ribose.yml +66 -0
- data/.rubocop.tb.yml +650 -0
- data/.rubocop.yml +15 -0
- data/.travis.yml +6 -0
- data/Gemfile +8 -0
- data/Gemfile.lock +255 -0
- data/LICENSE +25 -0
- data/README.adoc +17 -0
- data/bin/rspec +18 -0
- data/lib/relaton.rb +4 -0
- data/lib/relaton/processor.rb +16 -0
- data/lib/relaton/registry.rb +36 -0
- data/lib/relaton/relaton.rb +120 -0
- data/lib/relaton/version.rb +3 -0
- data/relaton.gemspec +48 -0
- data/spec/relaton/relaton_spec.rb +73 -0
- data/spec/spec_helper.rb +24 -0
- data/spec/support/_fr_standard_26020.html +828 -0
- data/spec/support/_fr_standard_32557.html +843 -0
- data/spec/support/_fr_standard_32579.html +768 -0
- data/spec/support/_fr_standard_39229.html +880 -0
- data/spec/support/_fr_standard_44361.html +606 -0
- data/spec/support/_fr_standard_53798.html +850 -0
- data/spec/support/_fr_standard_57104.html +805 -0
- data/spec/support/_fr_standard_66197.html +768 -0
- data/spec/support/_fr_standard_67039.html +704 -0
- data/spec/support/_fr_standard_73118.html +775 -0
- data/spec/support/_ru_standard_26020.html +831 -0
- data/spec/support/_ru_standard_32557.html +841 -0
- data/spec/support/_ru_standard_32579.html +772 -0
- data/spec/support/_ru_standard_39229.html +872 -0
- data/spec/support/_ru_standard_44361.html +597 -0
- data/spec/support/_ru_standard_53798.html +843 -0
- data/spec/support/_ru_standard_57104.html +803 -0
- data/spec/support/_ru_standard_66197.html +767 -0
- data/spec/support/_ru_standard_67039.html +695 -0
- data/spec/support/_ru_standard_73118.html +768 -0
- data/spec/support/_standard_26020.html +840 -0
- data/spec/support/_standard_32557.html +848 -0
- data/spec/support/_standard_32579.html +779 -0
- data/spec/support/_standard_39229.html +879 -0
- data/spec/support/_standard_44361.html +606 -0
- data/spec/support/_standard_53798.html +850 -0
- data/spec/support/_standard_57104.html +810 -0
- data/spec/support/_standard_66197.html +774 -0
- data/spec/support/_standard_67039.html +704 -0
- data/spec/support/_standard_73118.html +775 -0
- data/spec/support/algolia_resp_page_0.json +130 -0
- data/spec/support/algolia_resp_page_1.json +148 -0
- metadata +335 -0
data/.rubocop.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
# This project follows the Ribose OSS style guide.
|
2
|
+
# https://github.com/riboseinc/oss-guides
|
3
|
+
# All project-specific additions and overrides should be specified in this file.
|
4
|
+
|
5
|
+
inherit_from:
|
6
|
+
# Thoughtbot's style guide from: https://github.com/thoughtbot/guides
|
7
|
+
- ".rubocop.tb.yml"
|
8
|
+
# Overrides from Ribose
|
9
|
+
- ".rubocop.ribose.yml"
|
10
|
+
AllCops:
|
11
|
+
DisplayCopNames: false
|
12
|
+
StyleGuideCopsOnly: false
|
13
|
+
TargetRubyVersion: 2.5
|
14
|
+
Rails:
|
15
|
+
Enabled: true
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,255 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
relaton (0.0.1)
|
5
|
+
asciidoctor (~> 1.5.7)
|
6
|
+
gbbib (~> 0.1.0)
|
7
|
+
iev (~> 0.1.0)
|
8
|
+
iso-bib-item (~> 0.1.6)
|
9
|
+
isobib (~> 0.1.8)
|
10
|
+
rfcbib (~> 0.1.0)
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: https://rubygems.org/
|
14
|
+
specs:
|
15
|
+
algoliasearch (1.23.2)
|
16
|
+
httpclient (~> 2.8, >= 2.8.3)
|
17
|
+
json (>= 1.5.1)
|
18
|
+
asciidoctor (1.5.7.1)
|
19
|
+
asciidoctor-csand (0.3.1)
|
20
|
+
asciidoctor (~> 1.5.7)
|
21
|
+
asciidoctor-iso (>= 0.9.0)
|
22
|
+
asciimath
|
23
|
+
htmlentities (~> 4.3.4)
|
24
|
+
image_size
|
25
|
+
isodoc (>= 0.8.0)
|
26
|
+
mime-types
|
27
|
+
nokogiri
|
28
|
+
ruby-jing
|
29
|
+
ruby-xslt
|
30
|
+
thread_safe
|
31
|
+
uuidtools
|
32
|
+
asciidoctor-csd (0.4.1)
|
33
|
+
asciidoctor-iso (>= 0.9.0)
|
34
|
+
isodoc (>= 0.8.0)
|
35
|
+
asciidoctor-gb (0.3.1)
|
36
|
+
asciidoctor-iso (>= 0.9.0)
|
37
|
+
gbbib
|
38
|
+
isodoc (>= 0.8.0)
|
39
|
+
twitter_cldr
|
40
|
+
asciidoctor-iso (0.9.3)
|
41
|
+
asciidoctor (~> 1.5.7)
|
42
|
+
iso-bib-item (~> 0.1.6)
|
43
|
+
isobib (~> 0.1.8)
|
44
|
+
isodoc (>= 0.8)
|
45
|
+
ruby-jing
|
46
|
+
asciidoctor-m3d (0.3.2)
|
47
|
+
asciidoctor (~> 1.5.7)
|
48
|
+
asciidoctor-iso (>= 0.9.0)
|
49
|
+
asciimath
|
50
|
+
htmlentities (~> 4.3.4)
|
51
|
+
image_size
|
52
|
+
isodoc (>= 0.8.0)
|
53
|
+
mime-types
|
54
|
+
nokogiri
|
55
|
+
ruby-jing
|
56
|
+
ruby-xslt
|
57
|
+
thread_safe
|
58
|
+
uuidtools
|
59
|
+
asciidoctor-rfc (0.9.0)
|
60
|
+
asciidoctor (~> 1.5.7)
|
61
|
+
htmlentities (~> 4.3.4)
|
62
|
+
nokogiri
|
63
|
+
ruby-jing
|
64
|
+
thread_safe
|
65
|
+
asciidoctor-rsd (0.3.1)
|
66
|
+
asciidoctor (~> 1.5.7)
|
67
|
+
asciidoctor-iso (>= 0.8.0)
|
68
|
+
asciimath
|
69
|
+
htmlentities (~> 4.3.4)
|
70
|
+
image_size
|
71
|
+
isodoc (>= 0.7.0)
|
72
|
+
mime-types
|
73
|
+
nokogiri
|
74
|
+
ruby-jing
|
75
|
+
ruby-xslt
|
76
|
+
thread_safe
|
77
|
+
uuidtools
|
78
|
+
asciimath (1.0.4)
|
79
|
+
ast (2.4.0)
|
80
|
+
byebug (9.1.0)
|
81
|
+
camertron-eprun (1.1.1)
|
82
|
+
cldr-plurals-runtime-rb (1.0.1)
|
83
|
+
cnccs (0.1.1)
|
84
|
+
coderay (1.1.2)
|
85
|
+
diff-lcs (1.3)
|
86
|
+
docile (1.3.1)
|
87
|
+
duplicate (1.1.1)
|
88
|
+
equivalent-xml (0.6.0)
|
89
|
+
nokogiri (>= 1.4.3)
|
90
|
+
ffi (1.9.25)
|
91
|
+
formatador (0.2.5)
|
92
|
+
gbbib (0.1.3)
|
93
|
+
cnccs
|
94
|
+
iso-bib-item
|
95
|
+
guard (2.14.2)
|
96
|
+
formatador (>= 0.2.4)
|
97
|
+
listen (>= 2.7, < 4.0)
|
98
|
+
lumberjack (>= 1.0.12, < 2.0)
|
99
|
+
nenv (~> 0.1)
|
100
|
+
notiffany (~> 0.0)
|
101
|
+
pry (>= 0.9.12)
|
102
|
+
shellany (~> 0.0)
|
103
|
+
thor (>= 0.18.1)
|
104
|
+
guard-compat (1.2.1)
|
105
|
+
guard-rspec (4.7.3)
|
106
|
+
guard (~> 2.1)
|
107
|
+
guard-compat (~> 1.1)
|
108
|
+
rspec (>= 2.99.0, < 4.0)
|
109
|
+
html2doc (0.8.0)
|
110
|
+
asciimath
|
111
|
+
htmlentities (~> 4.3.4)
|
112
|
+
image_size
|
113
|
+
mime-types
|
114
|
+
nokogiri
|
115
|
+
ruby-xslt
|
116
|
+
thread_safe
|
117
|
+
uuidtools
|
118
|
+
htmlentities (4.3.4)
|
119
|
+
httpclient (2.8.3)
|
120
|
+
iev (0.1.0)
|
121
|
+
nokogiri
|
122
|
+
image_size (2.0.0)
|
123
|
+
iso-bib-item (0.1.10)
|
124
|
+
duplicate (~> 1.1.1)
|
125
|
+
isoics (~> 0.1.6)
|
126
|
+
nokogiri
|
127
|
+
isobib (0.1.9)
|
128
|
+
algoliasearch
|
129
|
+
iso-bib-item (~> 0.1.10)
|
130
|
+
isodoc (0.8.1)
|
131
|
+
asciimath
|
132
|
+
html2doc (>= 0.7.1)
|
133
|
+
htmlentities (~> 4.3.4)
|
134
|
+
image_size
|
135
|
+
liquid
|
136
|
+
mime-types
|
137
|
+
nokogiri
|
138
|
+
roman-numerals
|
139
|
+
ruby-xslt
|
140
|
+
sass
|
141
|
+
thread_safe
|
142
|
+
uuidtools
|
143
|
+
isoics (0.1.6)
|
144
|
+
jaro_winkler (1.5.1)
|
145
|
+
json (2.1.0)
|
146
|
+
liquid (4.0.0)
|
147
|
+
listen (3.1.5)
|
148
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
149
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
150
|
+
ruby_dep (~> 1.2)
|
151
|
+
lumberjack (1.0.13)
|
152
|
+
metanorma (0.2.5)
|
153
|
+
asciidoctor-csand (>= 0.3.0)
|
154
|
+
asciidoctor-csd (>= 0.4.0)
|
155
|
+
asciidoctor-gb (>= 0.3.0)
|
156
|
+
asciidoctor-iso (>= 0.9.1)
|
157
|
+
asciidoctor-m3d (>= 0.3.1)
|
158
|
+
asciidoctor-rfc (>= 0.9.0)
|
159
|
+
asciidoctor-rsd (>= 0.3.0)
|
160
|
+
isodoc (>= 0.8.0)
|
161
|
+
method_source (0.9.0)
|
162
|
+
mime-types (3.1)
|
163
|
+
mime-types-data (~> 3.2015)
|
164
|
+
mime-types-data (3.2016.0521)
|
165
|
+
mini_portile2 (2.3.0)
|
166
|
+
nenv (0.3.0)
|
167
|
+
nokogiri (1.8.4)
|
168
|
+
mini_portile2 (~> 2.3.0)
|
169
|
+
notiffany (0.1.1)
|
170
|
+
nenv (~> 0.1)
|
171
|
+
shellany (~> 0.0)
|
172
|
+
optout (0.0.2)
|
173
|
+
parallel (1.12.1)
|
174
|
+
parser (2.5.1.0)
|
175
|
+
ast (~> 2.4.0)
|
176
|
+
powerpack (0.1.2)
|
177
|
+
pry (0.11.3)
|
178
|
+
coderay (~> 1.1.0)
|
179
|
+
method_source (~> 0.9.0)
|
180
|
+
rainbow (3.0.0)
|
181
|
+
rake (12.3.1)
|
182
|
+
rb-fsevent (0.10.3)
|
183
|
+
rb-inotify (0.9.10)
|
184
|
+
ffi (>= 0.5.0, < 2)
|
185
|
+
rfcbib (0.1.1)
|
186
|
+
iso-bib-item (~> 0.1.10)
|
187
|
+
roman-numerals (0.3.0)
|
188
|
+
rspec (3.7.0)
|
189
|
+
rspec-core (~> 3.7.0)
|
190
|
+
rspec-expectations (~> 3.7.0)
|
191
|
+
rspec-mocks (~> 3.7.0)
|
192
|
+
rspec-core (3.7.1)
|
193
|
+
rspec-support (~> 3.7.0)
|
194
|
+
rspec-expectations (3.7.0)
|
195
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
196
|
+
rspec-support (~> 3.7.0)
|
197
|
+
rspec-mocks (3.7.0)
|
198
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
199
|
+
rspec-support (~> 3.7.0)
|
200
|
+
rspec-support (3.7.1)
|
201
|
+
rubocop (0.57.2)
|
202
|
+
jaro_winkler (~> 1.5.1)
|
203
|
+
parallel (~> 1.10)
|
204
|
+
parser (>= 2.5)
|
205
|
+
powerpack (~> 0.1)
|
206
|
+
rainbow (>= 2.2.2, < 4.0)
|
207
|
+
ruby-progressbar (~> 1.7)
|
208
|
+
unicode-display_width (~> 1.0, >= 1.0.1)
|
209
|
+
ruby-jing (0.0.1)
|
210
|
+
optout (>= 0.0.2)
|
211
|
+
ruby-progressbar (1.9.0)
|
212
|
+
ruby-xslt (0.9.10)
|
213
|
+
ruby_dep (1.5.0)
|
214
|
+
sass (3.5.6)
|
215
|
+
sass-listen (~> 4.0.0)
|
216
|
+
sass-listen (4.0.0)
|
217
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
218
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
219
|
+
shellany (0.0.1)
|
220
|
+
simplecov (0.16.1)
|
221
|
+
docile (~> 1.1)
|
222
|
+
json (>= 1.8, < 3)
|
223
|
+
simplecov-html (~> 0.10.0)
|
224
|
+
simplecov-html (0.10.2)
|
225
|
+
thor (0.20.0)
|
226
|
+
thread_safe (0.3.6)
|
227
|
+
timecop (0.9.1)
|
228
|
+
twitter_cldr (4.4.3)
|
229
|
+
camertron-eprun
|
230
|
+
cldr-plurals-runtime-rb (~> 1.0)
|
231
|
+
tzinfo
|
232
|
+
tzinfo (1.2.5)
|
233
|
+
thread_safe (~> 0.1)
|
234
|
+
unicode-display_width (1.4.0)
|
235
|
+
uuidtools (2.1.5)
|
236
|
+
|
237
|
+
PLATFORMS
|
238
|
+
ruby
|
239
|
+
|
240
|
+
DEPENDENCIES
|
241
|
+
bundler (~> 1.15)
|
242
|
+
byebug (~> 9.1)
|
243
|
+
equivalent-xml (~> 0.6)
|
244
|
+
guard (~> 2.14)
|
245
|
+
guard-rspec (~> 4.7)
|
246
|
+
metanorma (~> 0.2.5)
|
247
|
+
rake (~> 12.0)
|
248
|
+
relaton!
|
249
|
+
rspec (~> 3.6)
|
250
|
+
rubocop (~> 0.50)
|
251
|
+
simplecov (~> 0.15)
|
252
|
+
timecop (~> 0.9)
|
253
|
+
|
254
|
+
BUNDLED WITH
|
255
|
+
1.16.2
|
data/LICENSE
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
BSD 2-Clause License
|
2
|
+
|
3
|
+
Copyright (c) 2018, Ribose
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer.
|
11
|
+
|
12
|
+
* Redistributions in binary form must reproduce the above copyright notice,
|
13
|
+
this list of conditions and the following disclaimer in the documentation
|
14
|
+
and/or other materials provided with the distribution.
|
15
|
+
|
16
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
20
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.adoc
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
= relaton
|
2
|
+
|
3
|
+
gem for importing and caching bibliographic references to technical standards
|
4
|
+
|
5
|
+
```ruby
|
6
|
+
x = Relaton.fetch("ISO19011")
|
7
|
+
=> Relaton::Error "No such fetcher"
|
8
|
+
|
9
|
+
require 'relaton-iso'
|
10
|
+
x = Relaton.fetch("ISO19011")
|
11
|
+
=> <# Relaton::Iso @docidentifier: "ISO 19011:2011" ... >
|
12
|
+
|
13
|
+
x.to_xml
|
14
|
+
=> <bib-item ...>
|
15
|
+
```
|
16
|
+
|
17
|
+
|
data/bin/rspec
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# This file was generated by Bundler.
|
4
|
+
#
|
5
|
+
# The application 'rspec' is installed as part of a gem, and
|
6
|
+
# this file is here to facilitate running it.
|
7
|
+
#
|
8
|
+
|
9
|
+
require "pathname"
|
10
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path(
|
11
|
+
"../../Gemfile", Pathname.new(__FILE__).realpath
|
12
|
+
)
|
13
|
+
|
14
|
+
require "rubygems"
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
load Gem.bin_path("rspec-core", "rspec")
|
18
|
+
|
data/lib/relaton.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
class Error < StandardError
|
4
|
+
end
|
5
|
+
|
6
|
+
module Relaton
|
7
|
+
class Registry
|
8
|
+
include Singleton
|
9
|
+
|
10
|
+
attr_reader :processors
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
@processors = {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def register processor
|
17
|
+
raise Error unless processor < :: Relaton::Processor
|
18
|
+
p = processor.new
|
19
|
+
puts "[relaton] processor \"#{p.short}\" registered"
|
20
|
+
@processors[p.short] = p
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_processor(short)
|
24
|
+
@processors[short.to_sym]
|
25
|
+
end
|
26
|
+
|
27
|
+
def supported_processors
|
28
|
+
@processors.keys
|
29
|
+
end
|
30
|
+
|
31
|
+
def processors
|
32
|
+
@processors
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require_relative "registry"
|
2
|
+
|
3
|
+
module Relaton
|
4
|
+
class RelatonError < StandardError; end
|
5
|
+
|
6
|
+
class Db
|
7
|
+
#PREFIXES = ["GB Standard", "IETF", "ISO", "IEC", "IEV"]
|
8
|
+
|
9
|
+
SUPPORTED_GEMS = %w[ isobib rfcbib gbbib ].freeze
|
10
|
+
|
11
|
+
def initialize(global_cache, local_cache)
|
12
|
+
@bibdb = open_cache_biblio(global_cache)
|
13
|
+
@local_bibdb = open_cache_biblio(local_cache)
|
14
|
+
@bibdb_name = global_cache
|
15
|
+
@local_bibdb_name = local_cache
|
16
|
+
register_gems
|
17
|
+
@registry = Relaton::Registry.instance
|
18
|
+
end
|
19
|
+
|
20
|
+
def register_gems
|
21
|
+
puts "[relaton] detecting backends:"
|
22
|
+
SUPPORTED_GEMS.each do |b|
|
23
|
+
puts b
|
24
|
+
require b
|
25
|
+
rescue LoadError
|
26
|
+
puts "[relaton] backend #{b} not present"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# The class of reference requested is determined by the prefix of the code:
|
31
|
+
# GB Standard for gbbib, IETF for rfcbib, ISO or IEC or IEV for isobib
|
32
|
+
# @param code [String] the ISO standard Code to look up (e..g "ISO 9000")
|
33
|
+
# @param year [String] the year the standard was published (optional)
|
34
|
+
# @param opts [Hash] options; restricted to :all_parts if all-parts reference is required
|
35
|
+
# @return [String] Relaton XML serialisation of reference
|
36
|
+
def fetch(code, year = nil, opts = {})
|
37
|
+
stdclass = standard_class(code)
|
38
|
+
check_bibliocache(code, year, opts, stdclass)
|
39
|
+
end
|
40
|
+
|
41
|
+
def save()
|
42
|
+
save_cache_biblio(@bibdb, @bibdb_name)
|
43
|
+
save_cache_biblio(@local_bibdb, @local_bibdb_name)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def standard_class(code)
|
49
|
+
=begin
|
50
|
+
%r{^GB Standard }.match? code and return :gbbib
|
51
|
+
%r{^IETF }.match? code and return :rfcbib
|
52
|
+
%r{^(ISO|IEC)[ /]|IEV($| )}.match? code and return :isobib
|
53
|
+
=end
|
54
|
+
@registry.processors.each do |name, processor|
|
55
|
+
processor.prefix.match? code and return name
|
56
|
+
end
|
57
|
+
raise(RelatonError,
|
58
|
+
"#{code} does not have a recognised prefix: "\
|
59
|
+
"#{@registry.supported_processors.join(', ')}")
|
60
|
+
nil
|
61
|
+
end
|
62
|
+
|
63
|
+
def std_id(code, year, opts, _stdclass)
|
64
|
+
ret = code
|
65
|
+
ret += ":#{year}" if year
|
66
|
+
ret += " (all parts)" if opts[:all_parts]
|
67
|
+
ret
|
68
|
+
end
|
69
|
+
|
70
|
+
def check_bibliocache(code, year, opts, stdclass)
|
71
|
+
id = std_id(code, year, opts, stdclass)
|
72
|
+
return nil if @bibdb.nil? # signals we will not be using isobib
|
73
|
+
@bibdb[id] = nil unless is_valid_bibcache_entry?(@bibdb[id], year)
|
74
|
+
@bibdb[id] ||= new_bibcache_entry(code, year, opts, stdclass)
|
75
|
+
@local_bibdb[id] = @bibdb[id] if !@local_bibdb.nil? &&
|
76
|
+
!is_valid_bibcache_entry?(@local_bibdb[id], year)
|
77
|
+
return @local_bibdb[id]["bib"] unless @local_bibdb.nil?
|
78
|
+
@bibdb[id]["bib"]
|
79
|
+
end
|
80
|
+
|
81
|
+
# hash uses => , because the hash is imported from JSON
|
82
|
+
def new_bibcache_entry(code, year, opts, stdclass)
|
83
|
+
bib = @registry.processors[stdclass].get(code, year, opts)
|
84
|
+
return nil if bib.nil?
|
85
|
+
{ "fetched" => Date.today, "bib" => bib }
|
86
|
+
end
|
87
|
+
|
88
|
+
# if cached reference is undated, expire it after 60 days
|
89
|
+
def is_valid_bibcache_entry?(x, year)
|
90
|
+
x && x.is_a?(Hash) && x&.has_key?("bib") && x&.has_key?("fetched") &&
|
91
|
+
(year || Date.today - Date.iso8601(x["fetched"]) < 60)
|
92
|
+
end
|
93
|
+
|
94
|
+
def open_cache_biblio(filename)
|
95
|
+
biblio = {}
|
96
|
+
return {} unless !filename.nil? && Pathname.new(filename).file?
|
97
|
+
File.open(filename, "r") { |f| biblio = JSON.parse(f.read) }
|
98
|
+
biblio.each do |k, v|
|
99
|
+
biblio[k]&.fetch("bib") and
|
100
|
+
biblio[k]["bib"] = from_xml(biblio[k]["bib"])
|
101
|
+
end
|
102
|
+
biblio
|
103
|
+
end
|
104
|
+
|
105
|
+
def from_xml(entry)
|
106
|
+
entry # will be unmarshaller
|
107
|
+
end
|
108
|
+
|
109
|
+
def save_cache_biblio(biblio, filename)
|
110
|
+
return if biblio.nil? || filename.nil?
|
111
|
+
biblio.each do |k, v|
|
112
|
+
biblio[k]&.fetch("bib")&.respond_to? :to_xml and
|
113
|
+
biblio[k]["bib"] = biblio[k]["bib"].to_xml
|
114
|
+
end
|
115
|
+
File.open(filename, "w") do |b|
|
116
|
+
b << biblio.to_json
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|