iev 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6e6ba63fb8c18b055cf2915c1deddd1e92b77ddf7d78410b472e2602739e5d4
4
- data.tar.gz: 951d226d50c412cbe91c4beac9f2b3eb85c302c9d6deb2032171c68f9899c956
3
+ metadata.gz: 1dd87e06f2d1a737fd1233fc30716689f6c25812a8dcb18f74babd9e275d6345
4
+ data.tar.gz: 202a491fe395342bfc8a227e25442d87b8c4a85ed7c512aed621a721263359f5
5
5
  SHA512:
6
- metadata.gz: 9f404a23da498ae4aae84d826f96f434b95c059c0c94b9ad12e67d9fb00c21175fff9f5e79e565ec967743a081098a73697c5378061b19b2c623da33a6802786
7
- data.tar.gz: 6f51cd0ac4f6e975d1dfd41f65cddeab55c2d521da913dee581bcf3bde8a075282ab34ece5d7ebbe5a75aa1a11d325748dfca34bb906d18655c58a142bb30673
6
+ metadata.gz: 1e614046c3e48693dd000c611e2b25f8b8e028466c55e0b6297ac77d09be72c928d79db480850643aff3577d9edc4b08239816bf49db0dcc0288924739942e2c
7
+ data.tar.gz: 1ce017de6aed35931abbfb71d2d4a2155c2cb2aeb1163d39636a118b8313627f02a75e26c732703c6d559b3c01156efabb4b34009834e2699fc71a36e0490e5a
@@ -0,0 +1,3 @@
1
+ ruby:
2
+ Enabled: true
3
+ config_file: .rubocop.yml
@@ -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
@@ -12,30 +12,30 @@ GEM
12
12
  diff-lcs (1.3)
13
13
  docile (1.3.1)
14
14
  json (2.1.0)
15
- method_source (0.9.0)
16
- mini_portile2 (2.3.0)
17
- nokogiri (1.8.4)
18
- mini_portile2 (~> 2.3.0)
19
- pry (0.11.3)
15
+ method_source (0.9.2)
16
+ mini_portile2 (2.4.0)
17
+ nokogiri (1.10.1)
18
+ mini_portile2 (~> 2.4.0)
19
+ pry (0.12.2)
20
20
  coderay (~> 1.1.0)
21
21
  method_source (~> 0.9.0)
22
22
  pry-byebug (3.6.0)
23
23
  byebug (~> 10.0)
24
24
  pry (~> 0.10)
25
25
  rake (10.5.0)
26
- rspec (3.7.0)
27
- rspec-core (~> 3.7.0)
28
- rspec-expectations (~> 3.7.0)
29
- rspec-mocks (~> 3.7.0)
30
- rspec-core (3.7.1)
31
- rspec-support (~> 3.7.0)
32
- rspec-expectations (3.7.0)
26
+ rspec (3.8.0)
27
+ rspec-core (~> 3.8.0)
28
+ rspec-expectations (~> 3.8.0)
29
+ rspec-mocks (~> 3.8.0)
30
+ rspec-core (3.8.0)
31
+ rspec-support (~> 3.8.0)
32
+ rspec-expectations (3.8.2)
33
33
  diff-lcs (>= 1.2.0, < 2.0)
34
- rspec-support (~> 3.7.0)
35
- rspec-mocks (3.7.0)
34
+ rspec-support (~> 3.8.0)
35
+ rspec-mocks (3.8.0)
36
36
  diff-lcs (>= 1.2.0, < 2.0)
37
- rspec-support (~> 3.7.0)
38
- rspec-support (3.7.1)
37
+ rspec-support (~> 3.8.0)
38
+ rspec-support (3.8.0)
39
39
  simplecov (0.16.1)
40
40
  docile (~> 1.1)
41
41
  json (>= 1.8, < 3)
@@ -46,7 +46,7 @@ PLATFORMS
46
46
  ruby
47
47
 
48
48
  DEPENDENCIES
49
- bundler (~> 1.16)
49
+ bundler (~> 2.0.1)
50
50
  iev!
51
51
  pry-byebug
52
52
  rake (~> 10.0)
@@ -54,4 +54,4 @@ DEPENDENCIES
54
54
  simplecov
55
55
 
56
56
  BUNDLED WITH
57
- 1.16.2
57
+ 2.0.1
@@ -1,21 +1,25 @@
1
- The MIT License (MIT)
1
+ BSD 2-Clause License
2
2
 
3
- Copyright (c) 2018 Andrei Kislichenko
3
+ Copyright (c) 2018, Ribose
4
+ All rights reserved.
4
5
 
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
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
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
9
+ * Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
14
11
 
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
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.
@@ -1,5 +1,9 @@
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://img.shields.io/travis/metanorma/iev/master.svg["Build Status", link="https://travis-ci.com/metanorma/iev"]
5
+ image:https://codeclimate.com/github/metanorma/iev/badges/gpa.svg["Code Climate", link="https://codeclimate.com/github/metanorma/iev"]
6
+
3
7
  Fetch and encode IEV term from Electropedia.
4
8
 
5
9
  == Installation
@@ -10,8 +10,8 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = %q{IEV: Fetch and encode IEV term from Electropedia}
12
12
  spec.description = %q{IEV: Fetch and encode IEV term from Electropedia}
13
- spec.homepage = "https://github.com/riboseinc/iev"
14
- spec.license = "MIT"
13
+ spec.homepage = "https://github.com/metanorma/iev"
14
+ spec.license = "BSD-2-Clause"
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
17
  f.match(%r{^(test|spec|features)/})
@@ -19,8 +19,9 @@ Gem::Specification.new do |spec|
19
19
  spec.bindir = "exe"
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
21
  spec.require_paths = ["lib"]
22
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
22
23
 
23
- spec.add_development_dependency "bundler", "~> 1.16"
24
+ spec.add_development_dependency "bundler", "~> 2.0.1"
24
25
  spec.add_development_dependency 'pry-byebug'
25
26
  spec.add_development_dependency "rake", "~> 10.0"
26
27
  spec.add_development_dependency "rspec", "~> 3.0"
@@ -1,4 +1,5 @@
1
- require 'pstore'
1
+ # require 'pstore'
2
+ require_relative "db_cache"
2
3
 
3
4
  module Iev
4
5
  # Cache class.
@@ -22,65 +23,58 @@ module Iev
22
23
  private
23
24
 
24
25
  def check_bibliocache(code, lang)
25
- id = code + '/' + lang
26
+ id = code + "/" + lang
26
27
  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
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])
37
35
  end
38
36
  end
39
37
 
40
38
  def bib_retval(entry)
41
39
  # entry['term'] == 'not_found' ? '' : entry['term']
42
- entry['term']
40
+ # entry["term"]
41
+ entry =~ /^not_found/ ? nil : entry
43
42
  end
44
43
 
45
44
  # @return [Hash]
46
45
  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 }
46
+ Iev.get(code, lang)
50
47
  end
51
48
 
52
- # @param filename [String] DB filename
49
+ # @param dir [String] DB dir
53
50
  # @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
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 + "/."
59
+ warn "Global cache version is obsolete and cleared."
69
60
  end
61
+ db.set_version
62
+ elsif db.check_version? then db
70
63
  else
71
- save_cache_version db
64
+ warn "Local cache version is obsolete."
65
+ nil
72
66
  end
73
67
  end
74
68
 
75
- def check_cache_version(cache_db)
76
- cache_db.transaction { cache_db[:version] == VERSION }
77
- end
69
+ # def check_cache_version(cache_db)
70
+ # cache_db.transaction { cache_db[:version] == VERSION }
71
+ # end
78
72
 
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
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
85
79
  end
86
80
  end
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Iev
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
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.2.0
4
+ version: 0.2.1
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-07-30 00:00:00.000000000 Z
11
+ date: 2019-03-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.16'
19
+ version: 2.0.1
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: '1.16'
26
+ version: 2.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pry-byebug
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -102,7 +102,9 @@ extensions: []
102
102
  extra_rdoc_files: []
103
103
  files:
104
104
  - ".gitignore"
105
+ - ".hound.yml"
105
106
  - ".rspec"
107
+ - ".rubocop.yml"
106
108
  - ".travis.yml"
107
109
  - Gemfile
108
110
  - Gemfile.lock
@@ -114,10 +116,11 @@ files:
114
116
  - iev.gemspec
115
117
  - lib/iev.rb
116
118
  - lib/iev/db.rb
119
+ - lib/iev/db_cache.rb
117
120
  - lib/iev/version.rb
118
- homepage: https://github.com/riboseinc/iev
121
+ homepage: https://github.com/metanorma/iev
119
122
  licenses:
120
- - MIT
123
+ - BSD-2-Clause
121
124
  metadata: {}
122
125
  post_install_message:
123
126
  rdoc_options: []
@@ -127,7 +130,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
130
  requirements:
128
131
  - - ">="
129
132
  - !ruby/object:Gem::Version
130
- version: '0'
133
+ version: 2.3.0
131
134
  required_rubygems_version: !ruby/object:Gem::Requirement
132
135
  requirements:
133
136
  - - ">="