iev 0.3.3 → 0.3.5

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.
@@ -3,10 +3,10 @@
3
3
  # (c) Copyright 2020 Ribose Inc.
4
4
  #
5
5
 
6
- module IEV
7
- module CLI
6
+ module Iev
7
+ module Cli
8
8
  module CommandHelper
9
- include CLI::UI
9
+ include Cli::Ui
10
10
 
11
11
  protected
12
12
 
@@ -19,7 +19,7 @@ module IEV
19
19
  end
20
20
  end
21
21
 
22
- # Note: Implementation examples here:
22
+ # NOTE: Implementation examples here:
23
23
  # https://www.rubydoc.info/github/luislavena/sqlite3-ruby/SQLite3/Backup
24
24
  def save_db_to_file(src_db, dbfile)
25
25
  info "Saving database to a file..."
@@ -46,21 +46,23 @@ module IEV
46
46
  $IEV_PROFILE = options[:profile]
47
47
  $IEV_PROGRESS = options.fetch(:progress, !ENV["CI"])
48
48
 
49
- $IEV_DEBUG = options.to_h.
50
- select { |k, _| k.to_s.start_with? "debug_" }.
51
- transform_keys { |k| k.to_s.sub("debug_", "").to_sym }
49
+ $IEV_DEBUG = options.to_h
50
+ .select { |k, _| k.to_s.start_with? "debug_" }
51
+ .transform_keys do |k|
52
+ k.to_s.sub("debug_",
53
+ "").to_sym
54
+ end
52
55
  end
53
56
 
54
57
  def filter_dataset(db, options)
55
58
  query = db[:concepts]
56
59
 
57
60
  if options[:only_concepts]
58
- query = query.where(Sequel.ilike(:ievref, options[:only_concepts]))
61
+ query = query.where(Sequel.ilike(:ievref,
62
+ options[:only_concepts]))
59
63
  end
60
64
 
61
- if options[:only_languages]
62
- query = query.where(language: options[:only_languages].split(","))
63
- end
65
+ query = query.where(language: options[:only_languages].split(",")) if options[:only_languages]
64
66
 
65
67
  query
66
68
  end
data/lib/iev/cli/ui.rb CHANGED
@@ -3,13 +3,13 @@
3
3
  # (c) Copyright 2020 Ribose Inc.
4
4
  #
5
5
 
6
- module IEV
7
- module CLI
6
+ module Iev
7
+ module Cli
8
8
  # @todo
9
9
  # Make it thread-safe. Currently, calling UI methods from different
10
10
  # threads may result with mangled output. At first glance it seems like
11
11
  # something is wrong with carriage returns, but more research is needed.
12
- module UI
12
+ module Ui
13
13
  module_function
14
14
 
15
15
  def debug(*args)
@@ -42,11 +42,11 @@ module IEV
42
42
  module_function
43
43
 
44
44
  def clear_progress
45
- $IEV_PROGRESS ? "\r#{" " * 40}\r" : ""
45
+ $IEV_PROGRESS ? "\r#{' ' * 40}\r" : ""
46
46
  end
47
47
 
48
48
  def cli_out(level, *args)
49
- topic = Symbol === args[0] ? args.shift : nil
49
+ topic = args[0].is_a?(Symbol) ? args.shift : nil
50
50
  message = args.map(&:to_s).join(" ").chomp
51
51
  ui_tag = Thread.current[:iev_ui_tag]
52
52
 
data/lib/iev/cli.rb CHANGED
@@ -3,20 +3,20 @@
3
3
  # (c) Copyright 2020 Ribose Inc.
4
4
  #
5
5
 
6
- module IEV
7
- module CLI
6
+ module Iev
7
+ module Cli
8
8
  def self.start(arguments)
9
9
  Signal.trap("INT") do
10
- UI.info "Signal SIGINT received, quitting!"
10
+ Ui.info "Signal SIGINT received, quitting!"
11
11
  Kernel.exit(1)
12
12
  end
13
13
 
14
14
  Signal.trap("TERM") do
15
- UI.info "Signal SIGTERM received, quitting!"
15
+ Ui.info "Signal SIGTERM received, quitting!"
16
16
  Kernel.exit(1)
17
17
  end
18
18
 
19
- IEV::CLI::Command.start(arguments)
19
+ Iev::Cli::Command.start(arguments)
20
20
  end
21
21
  end
22
22
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module IEV
3
+ module Iev
4
4
  module Converter
5
5
  class MathmlToAsciimath
6
6
  using DataConversions
@@ -21,9 +21,7 @@ module IEV
21
21
  # any MathML or HTML formula.
22
22
  return input unless input&.match?(/<|&/)
23
23
 
24
- unless input.include?("<math>")
25
- return html_to_asciimath(input)
26
- end
24
+ return html_to_asciimath(input) unless input.include?("<math>")
27
25
 
28
26
  # puts "GOING TO MATHML MATH"
29
27
  # puts input
@@ -107,7 +105,7 @@ module IEV
107
105
  to_asciimath
108
106
  .children.to_s
109
107
  .gsub(/\]stem:\[/, "")
110
- .gsub(/<\/?[uo]l>/, ""),
108
+ .gsub(%r{</?[uo]l>}, ""),
111
109
  )
112
110
  end
113
111
 
@@ -116,81 +114,81 @@ module IEV
116
114
  end
117
115
 
118
116
  def html_entities_to_asciimath(input)
119
- input.gsub("&alpha;", "alpha").
120
- gsub("&beta;", "beta").
121
- gsub("&gamma;", "gamma").
122
- gsub("&Gamma;", "Gamma").
123
- gsub("&delta;", "delta").
124
- gsub("&Delta;", "Delta").
125
- gsub("&epsilon;", "epsilon").
126
- gsub("&varepsilon;", "varepsilon").
127
- gsub("&zeta;", "zeta").
128
- gsub("&eta;", "eta").
129
- gsub("&theta;", "theta").
130
- gsub("&Theta;", "Theta").
131
- gsub("&vartheta;", "vartheta").
132
- gsub("&iota;", "iota").
133
- gsub("&kappa;", "kappa").
134
- gsub("&lambda;", "lambda").
135
- gsub("&Lambda;", "Lambda").
136
- gsub("&mu;", "mu").
137
- gsub("&nu;", "nu").
138
- gsub("&xi;", "xi").
139
- gsub("&Xi;", "Xi").
140
- gsub("&pi;", "pi").
141
- gsub("&Pi;", "Pi").
142
- gsub("&rho;", "rho").
143
- gsub("&beta;", "beta").
144
- gsub("&sigma;", "sigma").
145
- gsub("&Sigma;", "Sigma").
146
- gsub("&tau;", "tau").
147
- gsub("&upsilon;", "upsilon").
148
- gsub("&phi;", "phi").
149
- gsub("&Phi;", "Phi").
150
- gsub("&varphi;", "varphi").
151
- gsub("&chi;", "chi").
152
- gsub("&psi;", "psi").
153
- gsub("&Psi;", "Psi").
154
- gsub("&omega;", "omega")
117
+ input.gsub("&alpha;", "alpha")
118
+ .gsub("&beta;", "beta")
119
+ .gsub("&gamma;", "gamma")
120
+ .gsub("&Gamma;", "Gamma")
121
+ .gsub("&delta;", "delta")
122
+ .gsub("&Delta;", "Delta")
123
+ .gsub("&epsilon;", "epsilon")
124
+ .gsub("&varepsilon;", "varepsilon")
125
+ .gsub("&zeta;", "zeta")
126
+ .gsub("&eta;", "eta")
127
+ .gsub("&theta;", "theta")
128
+ .gsub("&Theta;", "Theta")
129
+ .gsub("&vartheta;", "vartheta")
130
+ .gsub("&iota;", "iota")
131
+ .gsub("&kappa;", "kappa")
132
+ .gsub("&lambda;", "lambda")
133
+ .gsub("&Lambda;", "Lambda")
134
+ .gsub("&mu;", "mu")
135
+ .gsub("&nu;", "nu")
136
+ .gsub("&xi;", "xi")
137
+ .gsub("&Xi;", "Xi")
138
+ .gsub("&pi;", "pi")
139
+ .gsub("&Pi;", "Pi")
140
+ .gsub("&rho;", "rho")
141
+ .gsub("&beta;", "beta")
142
+ .gsub("&sigma;", "sigma")
143
+ .gsub("&Sigma;", "Sigma")
144
+ .gsub("&tau;", "tau")
145
+ .gsub("&upsilon;", "upsilon")
146
+ .gsub("&phi;", "phi")
147
+ .gsub("&Phi;", "Phi")
148
+ .gsub("&varphi;", "varphi")
149
+ .gsub("&chi;", "chi")
150
+ .gsub("&psi;", "psi")
151
+ .gsub("&Psi;", "Psi")
152
+ .gsub("&omega;", "omega")
155
153
  end
156
154
 
157
155
  def html_entities_to_stem(input)
158
- input.gsub("&alpha;", "stem:[alpha]").
159
- gsub("&beta;", "stem:[beta]").
160
- gsub("&gamma;", "stem:[gamma]").
161
- gsub("&Gamma;", "stem:[Gamma]").
162
- gsub("&delta;", "stem:[delta]").
163
- gsub("&Delta;", "stem:[Delta]").
164
- gsub("&epsilon;", "stem:[epsilon]").
165
- gsub("&varepsilon;", "stem:[varepsilon]").
166
- gsub("&zeta;", "stem:[zeta]").
167
- gsub("&eta;", "stem:[eta]").
168
- gsub("&theta;", "stem:[theta]").
169
- gsub("&Theta;", "stem:[Theta]").
170
- gsub("&vartheta;", "stem:[vartheta]").
171
- gsub("&iota;", "stem:[iota]").
172
- gsub("&kappa;", "stem:[kappa]").
173
- gsub("&lambda;", "stem:[lambda]").
174
- gsub("&Lambda;", "stem:[Lambda]").
175
- gsub("&mu;", "stem:[mu]").
176
- gsub("&nu;", "stem:[nu]").
177
- gsub("&xi;", "stem:[xi]").
178
- gsub("&Xi;", "stem:[Xi]").
179
- gsub("&pi;", "stem:[pi]").
180
- gsub("&Pi;", "stem:[Pi]").
181
- gsub("&rho;", "stem:[rho]").
182
- gsub("&beta;", "stem:[beta]").
183
- gsub("&sigma;", "stem:[sigma]").
184
- gsub("&Sigma;", "stem:[Sigma]").
185
- gsub("&tau;", "stem:[tau]").
186
- gsub("&upsilon;", "stem:[upsilon]").
187
- gsub("&phi;", "stem:[phi]").
188
- gsub("&Phi;", "stem:[Phi]").
189
- gsub("&varphi;", "stem:[varphi]").
190
- gsub("&chi;", "stem:[chi]").
191
- gsub("&psi;", "stem:[psi]").
192
- gsub("&Psi;", "stem:[Psi]").
193
- gsub("&omega;", "stem:[omega]")
156
+ input.gsub("&alpha;", "stem:[alpha]")
157
+ .gsub("&beta;", "stem:[beta]")
158
+ .gsub("&gamma;", "stem:[gamma]")
159
+ .gsub("&Gamma;", "stem:[Gamma]")
160
+ .gsub("&delta;", "stem:[delta]")
161
+ .gsub("&Delta;", "stem:[Delta]")
162
+ .gsub("&epsilon;", "stem:[epsilon]")
163
+ .gsub("&varepsilon;", "stem:[varepsilon]")
164
+ .gsub("&zeta;", "stem:[zeta]")
165
+ .gsub("&eta;", "stem:[eta]")
166
+ .gsub("&theta;", "stem:[theta]")
167
+ .gsub("&Theta;", "stem:[Theta]")
168
+ .gsub("&vartheta;", "stem:[vartheta]")
169
+ .gsub("&iota;", "stem:[iota]")
170
+ .gsub("&kappa;", "stem:[kappa]")
171
+ .gsub("&lambda;", "stem:[lambda]")
172
+ .gsub("&Lambda;", "stem:[Lambda]")
173
+ .gsub("&mu;", "stem:[mu]")
174
+ .gsub("&nu;", "stem:[nu]")
175
+ .gsub("&xi;", "stem:[xi]")
176
+ .gsub("&Xi;", "stem:[Xi]")
177
+ .gsub("&pi;", "stem:[pi]")
178
+ .gsub("&Pi;", "stem:[Pi]")
179
+ .gsub("&rho;", "stem:[rho]")
180
+ .gsub("&beta;", "stem:[beta]")
181
+ .gsub("&sigma;", "stem:[sigma]")
182
+ .gsub("&Sigma;", "stem:[Sigma]")
183
+ .gsub("&tau;", "stem:[tau]")
184
+ .gsub("&upsilon;", "stem:[upsilon]")
185
+ .gsub("&phi;", "stem:[phi]")
186
+ .gsub("&Phi;", "stem:[Phi]")
187
+ .gsub("&varphi;", "stem:[varphi]")
188
+ .gsub("&chi;", "stem:[chi]")
189
+ .gsub("&psi;", "stem:[psi]")
190
+ .gsub("&Psi;", "stem:[Psi]")
191
+ .gsub("&omega;", "stem:[omega]")
194
192
  end
195
193
  end
196
194
  end
data/lib/iev/converter.rb CHANGED
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module IEV
3
+ module Iev
4
4
  module Converter
5
5
  def self.mathml_to_asciimath(input)
6
- IEV::Converter::MathmlToAsciimath.convert(input)
6
+ Iev::Converter::MathmlToAsciimath.convert(input)
7
7
  end
8
8
  end
9
9
  end
@@ -3,7 +3,7 @@
3
3
  # (c) Copyright 2020 Ribose Inc.
4
4
  #
5
5
 
6
- module IEV
6
+ module Iev
7
7
  module DataConversions
8
8
  refine String do
9
9
  def decode_html!
@@ -18,9 +18,9 @@ module IEV
18
18
  # Normalize various encoding anomalies like `\uFEFF` in strings
19
19
  def sanitize!
20
20
  unicode_normalize!
21
- gsub!("\uFEFF", "")
22
- gsub!("\u2011", "-")
23
- gsub!("\u00a0", " ")
21
+ delete!("\uFEFF")
22
+ tr!("\u2011", "-")
23
+ tr!("\u00a0", " ")
24
24
  gsub!(/[\u2000-\u2006]/, " ")
25
25
  strip!
26
26
  nil
@@ -32,7 +32,7 @@ module IEV
32
32
  end
33
33
 
34
34
  def to_three_char_code
35
- IEV::Iso639Code.three_char_code(self).first
35
+ Iev::Iso639Code.three_char_code(self).first
36
36
  end
37
37
  end
38
38
  end
data/lib/iev/db.rb CHANGED
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # require 'pstore'
2
4
  require_relative "db_cache"
3
5
 
4
- module IEV
6
+ module Iev
5
7
  # Cache class.
6
8
  class Db
7
9
  # @param global_cache [String] filename of global DB
@@ -43,12 +45,12 @@ module IEV
43
45
 
44
46
  # @return [Hash]
45
47
  def new_bib_entry(code, lang)
46
- IEV.get(code, lang)
48
+ Iev.get(code, lang)
47
49
  end
48
50
 
49
51
  # @param dir [String] DB dir
50
52
  # @param global [TrueClass, FalseClass]
51
- # @return [IEV::DbCache, nil]
53
+ # @return [Iev::DbCache, nil]
52
54
  def open_cache_biblio(dir, global: true)
53
55
  return nil if dir.nil?
54
56
 
data/lib/iev/db_cache.rb CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "fileutils"
2
4
 
3
- module IEV
5
+ module Iev
4
6
  class DbCache
5
7
  # @return [String]
6
8
  attr_reader :dir
@@ -8,7 +10,7 @@ module IEV
8
10
  # @param dir [String] DB directory
9
11
  def initialize(dir)
10
12
  @dir = dir
11
- FileUtils::mkdir_p @dir
13
+ FileUtils.mkdir_p @dir
12
14
  file_version = "#{@dir}/version"
13
15
  File.exist? file_version or
14
16
  File.write file_version, VERSION, encoding: "utf-8"
@@ -21,7 +23,7 @@ module IEV
21
23
  return if value.nil?
22
24
 
23
25
  prefix_dir = "#{@dir}/#{prefix(key)}"
24
- FileUtils::mkdir_p prefix_dir
26
+ FileUtils.mkdir_p prefix_dir
25
27
  File.write filename(key), value, encoding: "utf-8"
26
28
  end
27
29
 
@@ -73,7 +75,7 @@ module IEV
73
75
  end
74
76
 
75
77
  # Set version of the DB to the gem version.
76
- # @return [IEV::DbCache]
78
+ # @return [Iev::DbCache]
77
79
  def set_version
78
80
  File.write "#{@dir}/version", VERSION, encoding: "utf-8"
79
81
  self
@@ -100,7 +102,7 @@ module IEV
100
102
  # if prefcode
101
103
  # "#{@dir}/#{prefcode[:prefix]}/#{prefcode[:code].gsub(/[-:\s\/]/, '_')}.xml"
102
104
  # else
103
- "#{@dir}/#{key.gsub(/[-:\s\/]/, '_')}.xml"
105
+ "#{@dir}/#{key.gsub(%r{[-:\s/]}, '_')}.xml"
104
106
  # end
105
107
  end
106
108
 
data/lib/iev/db_writer.rb CHANGED
@@ -3,9 +3,9 @@
3
3
  # (c) Copyright 2020 Ribose Inc.
4
4
  #
5
5
 
6
- module IEV
6
+ module Iev
7
7
  class DbWriter
8
- include CLI::UI
8
+ include Cli::Ui
9
9
  using DataConversions
10
10
 
11
11
  attr_reader :db
@@ -27,6 +27,7 @@ module IEV
27
27
  loop do
28
28
  row = row_enumerator.next
29
29
  next if row.empty?
30
+
30
31
  data = prepare_data(row, symbolized_title_row)
31
32
  display_progress(data)
32
33
  insert_data(data)
@@ -3,7 +3,7 @@
3
3
  # (c) Copyright 2020 Ribose Inc.
4
4
  #
5
5
 
6
- module IEV
6
+ module Iev
7
7
  # @todo This needs to be rewritten.
8
8
  class Iso639Code
9
9
  COUNTRY_CODES = YAML.load(IO.read(File.join(__dir__, "iso_639_2.yaml")))
@@ -11,12 +11,12 @@ module IEV
11
11
 
12
12
  def initialize(two_char_code)
13
13
  @code = case two_char_code.length
14
- when 2
15
- two_char_code
16
- else
17
- # This is to handle code "nl BE" in the IEV sheet
18
- two_char_code.split(" ").first
19
- end
14
+ when 2
15
+ two_char_code
16
+ else
17
+ # This is to handle code "nl BE" in the Iev sheet
18
+ two_char_code.split(" ").first
19
+ end
20
20
  end
21
21
 
22
22
  def find(code_type)
@@ -24,9 +24,7 @@ module IEV
24
24
  key if value["iso_639_1"] == @code.to_s && value[code_type]
25
25
  end
26
26
 
27
- if code.nil?
28
- raise StandardError.new("Iso639Code not found for '#{@code}'!")
29
- end
27
+ raise StandardError, "Iso639Code not found for '#{@code}'!" if code.nil?
30
28
 
31
29
  code
32
30
  end
@@ -41,7 +39,5 @@ module IEV
41
39
  def country_codes
42
40
  COUNTRY_CODES
43
41
  end
44
-
45
42
  end
46
43
  end
47
-
data/lib/iev/profiler.rb CHANGED
@@ -3,12 +3,12 @@
3
3
  # (c) Copyright 2020 Ribose Inc.
4
4
  #
5
5
 
6
- module IEV
6
+ module Iev
7
7
  class Profiler
8
8
  attr_reader :bench, :dir, :prefix, :profile
9
9
 
10
- def self.measure(prefix = nil, &block)
11
- new(prefix).run(&block)
10
+ def self.measure(prefix = nil, &)
11
+ new(prefix).run(&)
12
12
  end
13
13
 
14
14
  def initialize(prefix, dir: "profile")
@@ -16,15 +16,15 @@ module IEV
16
16
  @dir = dir
17
17
  end
18
18
 
19
- def run(&block)
20
- profiler_enabled? ? run!(&block) : block.call
19
+ def run(&)
20
+ profiler_enabled? ? run!(&) : yield
21
21
  end
22
22
 
23
- def run!(&block)
23
+ def run!
24
24
  retval = nil
25
25
  @profile = RubyProf.profile allow_exceptions: true do
26
26
  @bench = Benchmark.measure do
27
- retval = block.call
27
+ retval = yield
28
28
  end
29
29
  end
30
30
  retval
@@ -5,11 +5,11 @@
5
5
 
6
6
  require "singleton"
7
7
 
8
- module IEV
8
+ module Iev
9
9
  # Relaton cach singleton.
10
10
  class RelatonDb
11
11
  include Singleton
12
- include CLI::UI
12
+ include Cli::Ui
13
13
 
14
14
  def initialize
15
15
  info "Initializing Relaton..."
@@ -33,15 +33,12 @@ module IEV
33
33
 
34
34
  begin
35
35
  yield
36
+ rescue StandardError
37
+ raise unless curr_attempt <= attempts
36
38
 
37
- rescue
38
- if curr_attempt <= attempts
39
- sleep(2 ** curr_attempt * 0.1)
40
- curr_attempt += 1
41
- retry
42
- else
43
- raise
44
- end
39
+ sleep(2**curr_attempt * 0.1)
40
+ curr_attempt += 1
41
+ retry
45
42
  end
46
43
  end
47
44
 
@@ -52,11 +49,10 @@ module IEV
52
49
 
53
50
  begin
54
51
  yield
55
-
56
52
  ensure
57
53
  $stdout = original_stdout
58
54
  $stderr = original_stderr
59
- debug(:relaton, fake_out.string) if fake_out.pos > 0
55
+ debug(:relaton, fake_out.string) if fake_out.pos.positive?
60
56
  end
61
57
  end
62
58
  end