iev 0.1.0 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/macos.yml +38 -0
- data/.github/workflows/ubuntu.yml +56 -0
- data/.github/workflows/windows.yml +40 -0
- data/.gitignore +2 -0
- data/.hound.yml +3 -0
- data/.rubocop.yml +10 -0
- data/Gemfile.lock +34 -36
- data/LICENSE.txt +21 -17
- data/README.adoc +8 -0
- data/iev.gemspec +6 -6
- data/lib/iev.rb +1 -0
- data/lib/iev/db.rb +80 -0
- data/lib/iev/db_cache.rb +116 -0
- data/lib/iev/version.rb +1 -1
- metadata +24 -19
- data/.travis.yml +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e8ad6004f25a032c8aa40a9f59c248a0cfe1198035f66723e0614e9d49c446bf
|
4
|
+
data.tar.gz: fcbc700eef52ff5d14213da6f3ee9a9cb27386690361886f2644635fdc7f408f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b41dc9d69ba4c19ad1814b34f58dab35fe97d1aa01ec0fa5b923aca7c4fbfad8d253da8f3e1b0ac4c7dbec74656e41262260e1b6c1fea4615665ab3de63fc39
|
7
|
+
data.tar.gz: 37839fb1dd00ddf8b409e6d33d09b41b6f55a6ad84f5016076fcece3cbf26b781024e1ae6d5a8e0375cd9eb85ae91a515269fb3a8be67190037637379545c5d3
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
name: macos
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
branches: [ master ]
|
8
|
+
pull_request:
|
9
|
+
paths-ignore:
|
10
|
+
- .github/workflows/ubuntu.yml
|
11
|
+
- .github/workflows/windows.yml
|
12
|
+
|
13
|
+
jobs:
|
14
|
+
test-macos:
|
15
|
+
name: Test on Ruby ${{ matrix.ruby }} macOS
|
16
|
+
runs-on: macos-latest
|
17
|
+
continue-on-error: ${{ matrix.experimental }}
|
18
|
+
strategy:
|
19
|
+
fail-fast: false
|
20
|
+
matrix:
|
21
|
+
ruby: [ '2.6', '2.5', '2.4' ]
|
22
|
+
experimental: [false]
|
23
|
+
include:
|
24
|
+
- ruby: '2.7'
|
25
|
+
experimental: true
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@master
|
28
|
+
- name: Use Ruby
|
29
|
+
uses: actions/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby }}
|
32
|
+
- name: Update gems
|
33
|
+
run: |
|
34
|
+
sudo gem install bundler --force
|
35
|
+
bundle install --jobs 4 --retry 3
|
36
|
+
- name: Run specs
|
37
|
+
run: |
|
38
|
+
bundle exec rake
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
name: ubuntu
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
branches: [ master ]
|
8
|
+
tags:
|
9
|
+
- '*'
|
10
|
+
pull_request:
|
11
|
+
paths-ignore:
|
12
|
+
- .github/workflows/macos.yml
|
13
|
+
- .github/workflows/windows.yml
|
14
|
+
|
15
|
+
jobs:
|
16
|
+
test-linux:
|
17
|
+
name: Test on Ruby ${{ matrix.ruby }} Ubuntu
|
18
|
+
runs-on: ubuntu-latest
|
19
|
+
continue-on-error: ${{ matrix.experimental }}
|
20
|
+
strategy:
|
21
|
+
fail-fast: false
|
22
|
+
matrix:
|
23
|
+
ruby: [ '2.6', '2.5', '2.4' ]
|
24
|
+
experimental: [false]
|
25
|
+
include:
|
26
|
+
- ruby: '2.7'
|
27
|
+
experimental: true
|
28
|
+
steps:
|
29
|
+
- uses: actions/checkout@master
|
30
|
+
- name: Use Ruby
|
31
|
+
uses: actions/setup-ruby@v1
|
32
|
+
with:
|
33
|
+
ruby-version: ${{ matrix.ruby }}
|
34
|
+
- name: Update gems
|
35
|
+
run: |
|
36
|
+
gem install bundler
|
37
|
+
bundle install --jobs 4 --retry 3
|
38
|
+
- name: Run specs
|
39
|
+
run: |
|
40
|
+
bundle exec rake
|
41
|
+
- name: Trigger repositories
|
42
|
+
if: matrix.ruby == '2.6'
|
43
|
+
env:
|
44
|
+
GH_USERNAME: metanorma-ci
|
45
|
+
GH_ACCESS_TOKEN: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
|
46
|
+
run: |
|
47
|
+
curl -LO --retry 3 https://raw.githubusercontent.com/metanorma/metanorma-build-scripts/master/trigger-gh-actions.sh
|
48
|
+
[[ -f ".github/workflows/dependent_repos.env" ]] && source .github/workflows/dependent_repos.env
|
49
|
+
CLIENT_PAYLOAD=$(cat <<EOF
|
50
|
+
"{ "ref": "${GITHUB_REF}", "repo": "${GITHUB_REPOSITORY}" }"
|
51
|
+
EOF
|
52
|
+
)
|
53
|
+
for repo in $REPOS
|
54
|
+
do
|
55
|
+
sh trigger-gh-actions.sh $ORGANISATION $repo $GH_USERNAME $GH_ACCESS_TOKEN $GITHUB_REPOSITORY "$CLIENT_PAYLOAD"
|
56
|
+
done
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# Auto-generated by Cimas: Do not edit it manually!
|
2
|
+
# See https://github.com/metanorma/cimas
|
3
|
+
name: windows
|
4
|
+
|
5
|
+
on:
|
6
|
+
push:
|
7
|
+
branches: [ master ]
|
8
|
+
pull_request:
|
9
|
+
paths-ignore:
|
10
|
+
- .github/workflows/macos.yml
|
11
|
+
- .github/workflows/ubuntu.yml
|
12
|
+
|
13
|
+
jobs:
|
14
|
+
test-windows:
|
15
|
+
name: Test on Ruby ${{ matrix.ruby }} Windows
|
16
|
+
runs-on: windows-latest
|
17
|
+
continue-on-error: ${{ matrix.experimental }}
|
18
|
+
strategy:
|
19
|
+
fail-fast: false
|
20
|
+
matrix:
|
21
|
+
ruby: [ '2.6', '2.5', '2.4' ]
|
22
|
+
experimental: [false]
|
23
|
+
include:
|
24
|
+
- ruby: '2.7'
|
25
|
+
experimental: true
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@master
|
28
|
+
- name: Use Ruby
|
29
|
+
uses: actions/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby }}
|
32
|
+
- name: Update gems
|
33
|
+
shell: pwsh
|
34
|
+
run: |
|
35
|
+
gem install bundler
|
36
|
+
bundle config --local path vendor/bundle
|
37
|
+
bundle install --jobs 4 --retry 3
|
38
|
+
- name: Run specs
|
39
|
+
run: |
|
40
|
+
bundle exec rake
|
data/.gitignore
CHANGED
data/.hound.yml
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,10 @@
|
|
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
|
+
- https://raw.githubusercontent.com/riboseinc/oss-guides/master/ci/rubocop.yml
|
7
|
+
AllCops:
|
8
|
+
TargetRubyVersion: 2.3
|
9
|
+
Rails:
|
10
|
+
Enabled: true
|
data/Gemfile.lock
CHANGED
@@ -1,57 +1,55 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
iev (0.
|
5
|
-
nokogiri
|
4
|
+
iev (0.2.3)
|
5
|
+
nokogiri (>= 1.10.4)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
byebug (
|
11
|
-
coderay (1.1.
|
12
|
-
diff-lcs (1.
|
13
|
-
docile (1.3.
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
rspec-
|
28
|
-
rspec-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
rspec-expectations (3.7.0)
|
10
|
+
byebug (11.1.3)
|
11
|
+
coderay (1.1.3)
|
12
|
+
diff-lcs (1.4.4)
|
13
|
+
docile (1.3.2)
|
14
|
+
method_source (1.0.0)
|
15
|
+
mini_portile2 (2.4.0)
|
16
|
+
nokogiri (1.10.10)
|
17
|
+
mini_portile2 (~> 2.4.0)
|
18
|
+
pry (0.13.1)
|
19
|
+
coderay (~> 1.1)
|
20
|
+
method_source (~> 1.0)
|
21
|
+
pry-byebug (3.9.0)
|
22
|
+
byebug (~> 11.0)
|
23
|
+
pry (~> 0.13.0)
|
24
|
+
rake (13.0.1)
|
25
|
+
rspec (3.9.0)
|
26
|
+
rspec-core (~> 3.9.0)
|
27
|
+
rspec-expectations (~> 3.9.0)
|
28
|
+
rspec-mocks (~> 3.9.0)
|
29
|
+
rspec-core (3.9.2)
|
30
|
+
rspec-support (~> 3.9.3)
|
31
|
+
rspec-expectations (3.9.2)
|
33
32
|
diff-lcs (>= 1.2.0, < 2.0)
|
34
|
-
rspec-support (~> 3.
|
35
|
-
rspec-mocks (3.
|
33
|
+
rspec-support (~> 3.9.0)
|
34
|
+
rspec-mocks (3.9.1)
|
36
35
|
diff-lcs (>= 1.2.0, < 2.0)
|
37
|
-
rspec-support (~> 3.
|
38
|
-
rspec-support (3.
|
39
|
-
simplecov (0.
|
36
|
+
rspec-support (~> 3.9.0)
|
37
|
+
rspec-support (3.9.3)
|
38
|
+
simplecov (0.18.5)
|
40
39
|
docile (~> 1.1)
|
41
|
-
|
42
|
-
|
43
|
-
simplecov-html (0.10.2)
|
40
|
+
simplecov-html (~> 0.11)
|
41
|
+
simplecov-html (0.12.2)
|
44
42
|
|
45
43
|
PLATFORMS
|
46
44
|
ruby
|
47
45
|
|
48
46
|
DEPENDENCIES
|
49
|
-
bundler
|
47
|
+
bundler
|
50
48
|
iev!
|
51
49
|
pry-byebug
|
52
|
-
rake (~>
|
50
|
+
rake (~> 13.0)
|
53
51
|
rspec (~> 3.0)
|
54
52
|
simplecov
|
55
53
|
|
56
54
|
BUNDLED WITH
|
57
|
-
1.
|
55
|
+
2.1.4
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,25 @@
|
|
1
|
-
|
1
|
+
BSD 2-Clause License
|
2
2
|
|
3
|
-
Copyright (c) 2018
|
3
|
+
Copyright (c) 2018, Ribose
|
4
|
+
All rights reserved.
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
11
8
|
|
12
|
-
|
13
|
-
|
9
|
+
* Redistributions of source code must retain the above copyright notice, this
|
10
|
+
list of conditions and the following disclaimer.
|
14
11
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
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
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
= Iev
|
2
2
|
|
3
|
+
image:https://img.shields.io/gem/v/iev.svg["Gem Version", link="https://rubygems.org/gems/iev"]
|
4
|
+
image:https://github.com/metanorma/iev/workflows/ubuntu/badge.svg["Ubuntu Build Status", link="https://github.com/metanorma/iev/actions?query=workflow%3Aubuntu"]
|
5
|
+
image:https://github.com/metanorma/iev/workflows/macos/badge.svg["OSX Build Status", link="https://github.com/metanorma/iev/actions?query=workflow%3Amacos"]
|
6
|
+
image:https://github.com/metanorma/iev/workflows/windows/badge.svg["Windows Build Status", link="https://github.com/metanorma/iev/actions?query=workflow%3Awindows"]
|
7
|
+
image:https://codeclimate.com/github/metanorma/iev/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/iev"]
|
8
|
+
image:https://img.shields.io/github/issues-pr-raw/metanorma/iev.svg["Pull Requests", link="https://github.com/metanorma/iev/pulls"]
|
9
|
+
image:https://img.shields.io/github/commits-since/metanorma/iev/latest.svg["Commits since latest",link="https://github.com/metanorma/iev/releases"]
|
10
|
+
|
3
11
|
Fetch and encode IEV term from Electropedia.
|
4
12
|
|
5
13
|
== Installation
|
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"
|
@@ -11,8 +10,8 @@ Gem::Specification.new do |spec|
|
|
11
10
|
|
12
11
|
spec.summary = %q{IEV: Fetch and encode IEV term from Electropedia}
|
13
12
|
spec.description = %q{IEV: Fetch and encode IEV term from Electropedia}
|
14
|
-
spec.homepage = "https://github.com/
|
15
|
-
spec.license = "
|
13
|
+
spec.homepage = "https://github.com/metanorma/iev"
|
14
|
+
spec.license = "BSD-2-Clause"
|
16
15
|
|
17
16
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
17
|
f.match(%r{^(test|spec|features)/})
|
@@ -20,12 +19,13 @@ Gem::Specification.new do |spec|
|
|
20
19
|
spec.bindir = "exe"
|
21
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
21
|
spec.require_paths = ["lib"]
|
22
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler"
|
24
|
+
spec.add_development_dependency "bundler"
|
25
25
|
spec.add_development_dependency 'pry-byebug'
|
26
|
-
spec.add_development_dependency "rake", "~>
|
26
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
27
27
|
spec.add_development_dependency "rspec", "~> 3.0"
|
28
28
|
spec.add_development_dependency 'simplecov'
|
29
29
|
|
30
|
-
spec.add_dependency 'nokogiri'
|
30
|
+
spec.add_dependency 'nokogiri', ">= 1.10.4"
|
31
31
|
end
|
data/lib/iev.rb
CHANGED
data/lib/iev/db.rb
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
# require 'pstore'
|
2
|
+
require_relative "db_cache"
|
3
|
+
|
4
|
+
module Iev
|
5
|
+
# Cache class.
|
6
|
+
class Db
|
7
|
+
# @param global_cache [String] filename of global DB
|
8
|
+
# @param local_cache [String] filename of local DB
|
9
|
+
def initialize(global_cache, local_cache)
|
10
|
+
@db = open_cache_biblio(global_cache)
|
11
|
+
@local_db = open_cache_biblio(local_cache, global: false)
|
12
|
+
@db_name = global_cache
|
13
|
+
@local_db_name = local_cache
|
14
|
+
end
|
15
|
+
|
16
|
+
# @param [String] code for example "103-01-02"
|
17
|
+
# @param [String] lang language code, for examle "en"
|
18
|
+
# @return [String] Relaton XML serialisation of reference
|
19
|
+
def fetch(code, lang)
|
20
|
+
check_bibliocache(code, lang)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def check_bibliocache(code, lang)
|
26
|
+
id = code + "/" + lang
|
27
|
+
return bib_retval(new_bib_entry(code, lang)) if @db.nil?
|
28
|
+
|
29
|
+
# @db.delete(id) unless valid_bib_entry?(@db[id])
|
30
|
+
@db[id] ||= new_bib_entry(code, lang)
|
31
|
+
if @local_db.nil? then bib_retval(@db[id])
|
32
|
+
else
|
33
|
+
@local_db[id] ||= @db[id]
|
34
|
+
bib_retval(@local_db[id])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def bib_retval(entry)
|
39
|
+
# entry['term'] == 'not_found' ? '' : entry['term']
|
40
|
+
# entry["term"]
|
41
|
+
entry =~ /^not_found/ ? nil : entry
|
42
|
+
end
|
43
|
+
|
44
|
+
# @return [Hash]
|
45
|
+
def new_bib_entry(code, lang)
|
46
|
+
Iev.get(code, lang)
|
47
|
+
end
|
48
|
+
|
49
|
+
# @param dir [String] DB dir
|
50
|
+
# @param global [TrueClass, FalseClass]
|
51
|
+
# @return [Iev::DbCache, nil]
|
52
|
+
def open_cache_biblio(dir, global: true)
|
53
|
+
return nil if dir.nil?
|
54
|
+
|
55
|
+
db = DbCache.new dir
|
56
|
+
if global
|
57
|
+
unless db.check_version?
|
58
|
+
FileUtils.rm_rf(Dir.glob(File.join(dir, '*')), secure: true)
|
59
|
+
warn "Global cache version is obsolete and cleared."
|
60
|
+
end
|
61
|
+
db.set_version
|
62
|
+
elsif db.check_version? then db
|
63
|
+
else
|
64
|
+
warn "Local cache version is obsolete."
|
65
|
+
nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
# def check_cache_version(cache_db)
|
70
|
+
# cache_db.transaction { cache_db[:version] == VERSION }
|
71
|
+
# end
|
72
|
+
|
73
|
+
# def save_cache_version(cache_db)
|
74
|
+
# unless File.exist? cache_db.path
|
75
|
+
# cache_db.transaction { cache_db[:version] = VERSION }
|
76
|
+
# end
|
77
|
+
# cache_db
|
78
|
+
# end
|
79
|
+
end
|
80
|
+
end
|
data/lib/iev/db_cache.rb
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
module Iev
|
4
|
+
class DbCache
|
5
|
+
# @return [String]
|
6
|
+
attr_reader :dir
|
7
|
+
|
8
|
+
# @param dir [String] DB directory
|
9
|
+
def initialize(dir)
|
10
|
+
@dir = dir
|
11
|
+
FileUtils::mkdir_p @dir
|
12
|
+
file_version = "#{@dir}/version"
|
13
|
+
File.write file_version, VERSION, encoding: "utf-8" unless File.exist? file_version
|
14
|
+
end
|
15
|
+
|
16
|
+
# Save item
|
17
|
+
# @param key [String]
|
18
|
+
# @param value [String] Bibitem xml serialization
|
19
|
+
def []=(key, value)
|
20
|
+
return if value.nil?
|
21
|
+
|
22
|
+
prefix_dir = "#{@dir}/#{prefix(key)}"
|
23
|
+
FileUtils::mkdir_p prefix_dir
|
24
|
+
File.write filename(key), value, encoding: "utf-8"
|
25
|
+
end
|
26
|
+
|
27
|
+
# Read item
|
28
|
+
# @param key [String]
|
29
|
+
# @return [String]
|
30
|
+
def [](key)
|
31
|
+
file = filename key
|
32
|
+
return unless File.exist? file
|
33
|
+
|
34
|
+
File.read(file, encoding: "utf-8")
|
35
|
+
end
|
36
|
+
|
37
|
+
# Return fetched date
|
38
|
+
# @param key [String]
|
39
|
+
# @return [String]
|
40
|
+
def fetched(key)
|
41
|
+
value = self[key]
|
42
|
+
return unless value
|
43
|
+
|
44
|
+
# if value =~ /^not_found/
|
45
|
+
# value.match(/\d{4}-\d{2}-\d{2}/).to_s
|
46
|
+
# else
|
47
|
+
doc = Nokogiri::XML value
|
48
|
+
doc.at("/bibitem/fetched")&.text
|
49
|
+
# end
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns all items
|
53
|
+
# @return [Array<Hash>]
|
54
|
+
def all
|
55
|
+
Dir.glob("#{@dir}/**/*.xml").sort.map do |f|
|
56
|
+
File.read(f, encoding: "utf-8")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# Delete item
|
61
|
+
# @param key [String]
|
62
|
+
def delete(key)
|
63
|
+
file = filename key
|
64
|
+
File.delete file if File.exist? file
|
65
|
+
end
|
66
|
+
|
67
|
+
# Check if version of the DB match to the gem version.
|
68
|
+
# @return [TrueClass, FalseClass]
|
69
|
+
def check_version?
|
70
|
+
v = File.read @dir + "/version", encoding: "utf-8"
|
71
|
+
v == VERSION
|
72
|
+
end
|
73
|
+
|
74
|
+
# Set version of the DB to the gem version.
|
75
|
+
# @return [Iev::DbCache]
|
76
|
+
def set_version
|
77
|
+
File.write @dir + "/version", VERSION, encoding: "utf-8"
|
78
|
+
self
|
79
|
+
end
|
80
|
+
|
81
|
+
# if cached reference is undated, expire it after 60 days
|
82
|
+
# @param key [String]
|
83
|
+
# @param year [String]
|
84
|
+
# def valid_entry?(key)
|
85
|
+
# datestr = fetched key
|
86
|
+
# return false unless datestr
|
87
|
+
|
88
|
+
# date = Date.parse datestr
|
89
|
+
# year || Date.today - date < 60
|
90
|
+
# end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
# Return item's file name
|
95
|
+
# @param key [String]
|
96
|
+
# @return [String]
|
97
|
+
def filename(key)
|
98
|
+
# prefcode = key.downcase.match /^(?<prefix>[^\(]+)\((?<code>[^\)]+)/
|
99
|
+
# if prefcode
|
100
|
+
# "#{@dir}/#{prefcode[:prefix]}/#{prefcode[:code].gsub(/[-:\s\/]/, '_')}.xml"
|
101
|
+
# else
|
102
|
+
"#{@dir}/#{key.gsub(/[-:\s\/]/, '_')}.xml"
|
103
|
+
# end
|
104
|
+
end
|
105
|
+
|
106
|
+
# Return item's subdir
|
107
|
+
# @param key [String]
|
108
|
+
# @return [String]
|
109
|
+
def prefix(key)
|
110
|
+
# @registry.processors.detect do |_n, p|
|
111
|
+
# /^#{p.prefix}/.match(key) || processor.defaultprefix.match(key)
|
112
|
+
# end[1].prefix.downcase
|
113
|
+
key.downcase.match(/^[^\(]+(?=\()/).to_s
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
data/lib/iev/version.rb
CHANGED
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iev
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: pry-byebug
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '13.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '13.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 1.10.4
|
90
90
|
type: :runtime
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - ">="
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
96
|
+
version: 1.10.4
|
97
97
|
description: 'IEV: Fetch and encode IEV term from Electropedia'
|
98
98
|
email:
|
99
99
|
- open.source@ribose.com
|
@@ -101,9 +101,13 @@ executables: []
|
|
101
101
|
extensions: []
|
102
102
|
extra_rdoc_files: []
|
103
103
|
files:
|
104
|
+
- ".github/workflows/macos.yml"
|
105
|
+
- ".github/workflows/ubuntu.yml"
|
106
|
+
- ".github/workflows/windows.yml"
|
104
107
|
- ".gitignore"
|
108
|
+
- ".hound.yml"
|
105
109
|
- ".rspec"
|
106
|
-
- ".
|
110
|
+
- ".rubocop.yml"
|
107
111
|
- Gemfile
|
108
112
|
- Gemfile.lock
|
109
113
|
- LICENSE.txt
|
@@ -113,12 +117,14 @@ files:
|
|
113
117
|
- bin/setup
|
114
118
|
- iev.gemspec
|
115
119
|
- lib/iev.rb
|
120
|
+
- lib/iev/db.rb
|
121
|
+
- lib/iev/db_cache.rb
|
116
122
|
- lib/iev/version.rb
|
117
|
-
homepage: https://github.com/
|
123
|
+
homepage: https://github.com/metanorma/iev
|
118
124
|
licenses:
|
119
|
-
-
|
125
|
+
- BSD-2-Clause
|
120
126
|
metadata: {}
|
121
|
-
post_install_message:
|
127
|
+
post_install_message:
|
122
128
|
rdoc_options: []
|
123
129
|
require_paths:
|
124
130
|
- lib
|
@@ -126,16 +132,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
132
|
requirements:
|
127
133
|
- - ">="
|
128
134
|
- !ruby/object:Gem::Version
|
129
|
-
version:
|
135
|
+
version: 2.4.0
|
130
136
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
137
|
requirements:
|
132
138
|
- - ">="
|
133
139
|
- !ruby/object:Gem::Version
|
134
140
|
version: '0'
|
135
141
|
requirements: []
|
136
|
-
|
137
|
-
|
138
|
-
signing_key:
|
142
|
+
rubygems_version: 3.0.3
|
143
|
+
signing_key:
|
139
144
|
specification_version: 4
|
140
145
|
summary: 'IEV: Fetch and encode IEV term from Electropedia'
|
141
146
|
test_files: []
|