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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bbb6ebdd3c3550b6575076657bc618d97198eae3
4
- data.tar.gz: 1d37af1476af7580f13e7eccf9dfe525431f04b7
2
+ SHA256:
3
+ metadata.gz: e6e6ba63fb8c18b055cf2915c1deddd1e92b77ddf7d78410b472e2602739e5d4
4
+ data.tar.gz: 951d226d50c412cbe91c4beac9f2b3eb85c302c9d6deb2032171c68f9899c956
5
5
  SHA512:
6
- metadata.gz: 8867b1ac27da0c94c3ee61b3264a30a322d934b32c654f58a895220f2d427693853942fe7868a6a21a01c41471a8727b4dbc464d164d8131e7d5e530b72a7990
7
- data.tar.gz: 2f1417fb05321824961e0a2796df430a3fa3b6367487a5f6e7d38699d6dfbdf7df679ddbffce263786a0ab427e332130f3c1b9f1bf24ef2e7e495aecac66a6f9
6
+ metadata.gz: 9f404a23da498ae4aae84d826f96f434b95c059c0c94b9ad12e67d9fb00c21175fff9f5e79e565ec967743a081098a73697c5378061b19b2c623da33a6802786
7
+ data.tar.gz: 6f51cd0ac4f6e975d1dfd41f65cddeab55c2d521da913dee581bcf3bde8a075282ab34ece5d7ebbe5a75aa1a11d325748dfca34bb906d18655c58a142bb30673
data/.gitignore CHANGED
@@ -6,6 +6,8 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /testcache
10
+ /testcache2
9
11
 
10
12
  # rspec failure tracking
11
13
  .rspec_status
data/.travis.yml CHANGED
@@ -1,5 +1,14 @@
1
1
  sudo: false
2
2
  language: ruby
3
+
3
4
  rvm:
4
- - 2.4.0
5
+ - 2.5
6
+ - 2.4
7
+ - 2.3
8
+ - ruby-head
9
+
5
10
  before_install: gem install bundler -v 1.16.1
11
+
12
+ matrix:
13
+ allow_failures:
14
+ - rvm: ruby-head
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iev (0.1.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.3)
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.1
57
+ 1.16.2
data/iev.gemspec CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "iev/version"
data/lib/iev.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "iev/version"
2
+ require "iev/db"
2
3
  require "open-uri"
3
4
  require "nokogiri"
4
5
 
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
@@ -1,3 +1,3 @@
1
1
  module Iev
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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-06-22 00:00:00.000000000 Z
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.12
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'