iev 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/.travis.yml +10 -1
- data/Gemfile.lock +3 -3
- data/iev.gemspec +0 -1
- data/lib/iev.rb +1 -0
- data/lib/iev/db.rb +86 -0
- data/lib/iev/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e6e6ba63fb8c18b055cf2915c1deddd1e92b77ddf7d78410b472e2602739e5d4
|
4
|
+
data.tar.gz: 951d226d50c412cbe91c4beac9f2b3eb85c302c9d6deb2032171c68f9899c956
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f404a23da498ae4aae84d826f96f434b95c059c0c94b9ad12e67d9fb00c21175fff9f5e79e565ec967743a081098a73697c5378061b19b2c623da33a6802786
|
7
|
+
data.tar.gz: 6f51cd0ac4f6e975d1dfd41f65cddeab55c2d521da913dee581bcf3bde8a075282ab34ece5d7ebbe5a75aa1a11d325748dfca34bb906d18655c58a142bb30673
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
iev (0.
|
4
|
+
iev (0.2.0)
|
5
5
|
nokogiri
|
6
6
|
|
7
7
|
GEM
|
@@ -14,7 +14,7 @@ GEM
|
|
14
14
|
json (2.1.0)
|
15
15
|
method_source (0.9.0)
|
16
16
|
mini_portile2 (2.3.0)
|
17
|
-
nokogiri (1.8.
|
17
|
+
nokogiri (1.8.4)
|
18
18
|
mini_portile2 (~> 2.3.0)
|
19
19
|
pry (0.11.3)
|
20
20
|
coderay (~> 1.1.0)
|
@@ -54,4 +54,4 @@ DEPENDENCIES
|
|
54
54
|
simplecov
|
55
55
|
|
56
56
|
BUNDLED WITH
|
57
|
-
1.16.
|
57
|
+
1.16.2
|
data/iev.gemspec
CHANGED
data/lib/iev.rb
CHANGED
data/lib/iev/db.rb
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'pstore'
|
2
|
+
|
3
|
+
module Iev
|
4
|
+
# Cache class.
|
5
|
+
class Db
|
6
|
+
# @param global_cache [String] filename of global DB
|
7
|
+
# @param local_cache [String] filename of local DB
|
8
|
+
def initialize(global_cache, local_cache)
|
9
|
+
@db = open_cache_biblio(global_cache)
|
10
|
+
@local_db = open_cache_biblio(local_cache, global: false)
|
11
|
+
@db_name = global_cache
|
12
|
+
@local_db_name = local_cache
|
13
|
+
end
|
14
|
+
|
15
|
+
# @param [String] code for example "103-01-02"
|
16
|
+
# @param [String] lang language code, for examle "en"
|
17
|
+
# @return [String] Relaton XML serialisation of reference
|
18
|
+
def fetch(code, lang)
|
19
|
+
check_bibliocache(code, lang)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def check_bibliocache(code, lang)
|
25
|
+
id = code + '/' + lang
|
26
|
+
return bib_retval(new_bib_entry(code, lang)) if @db.nil?
|
27
|
+
@db.transaction do
|
28
|
+
# @db.delete(id) unless valid_bib_entry?(@db[id])
|
29
|
+
@db[id] ||= new_bib_entry(code, lang)
|
30
|
+
if @local_db.nil? then bib_retval(@db[id])
|
31
|
+
else
|
32
|
+
@local_db.transaction do
|
33
|
+
@local_db[id] ||= @db[id]
|
34
|
+
bib_retval(@local_db[id])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def bib_retval(entry)
|
41
|
+
# entry['term'] == 'not_found' ? '' : entry['term']
|
42
|
+
entry['term']
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Hash]
|
46
|
+
def new_bib_entry(code, lang)
|
47
|
+
term = Iev.get(code, lang)
|
48
|
+
# term = 'not_found' if term.nil? || term.empty?
|
49
|
+
{ 'term' => term, 'definition' => nil }
|
50
|
+
end
|
51
|
+
|
52
|
+
# @param filename [String] DB filename
|
53
|
+
# @param global [TrueClass, FalseClass]
|
54
|
+
# @return [PStore]
|
55
|
+
def open_cache_biblio(filename, global: true)
|
56
|
+
return nil if filename.nil?
|
57
|
+
db = PStore.new filename
|
58
|
+
if File.exist? filename
|
59
|
+
if global
|
60
|
+
unless check_cache_version(db)
|
61
|
+
File.delete filename
|
62
|
+
warn 'Global cache version is obsolete and cleared.'
|
63
|
+
end
|
64
|
+
save_cache_version db
|
65
|
+
elsif check_cache_version(db) then db
|
66
|
+
else
|
67
|
+
warn 'Local cache version is obsolete.'
|
68
|
+
nil
|
69
|
+
end
|
70
|
+
else
|
71
|
+
save_cache_version db
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def check_cache_version(cache_db)
|
76
|
+
cache_db.transaction { cache_db[:version] == VERSION }
|
77
|
+
end
|
78
|
+
|
79
|
+
def save_cache_version(cache_db)
|
80
|
+
unless File.exist? cache_db.path
|
81
|
+
cache_db.transaction { cache_db[:version] = VERSION }
|
82
|
+
end
|
83
|
+
cache_db
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/lib/iev/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- bin/setup
|
114
114
|
- iev.gemspec
|
115
115
|
- lib/iev.rb
|
116
|
+
- lib/iev/db.rb
|
116
117
|
- lib/iev/version.rb
|
117
118
|
homepage: https://github.com/riboseinc/iev
|
118
119
|
licenses:
|
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
135
|
version: '0'
|
135
136
|
requirements: []
|
136
137
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.6
|
138
|
+
rubygems_version: 2.7.6
|
138
139
|
signing_key:
|
139
140
|
specification_version: 4
|
140
141
|
summary: 'IEV: Fetch and encode IEV term from Electropedia'
|