nuva 0.1.6 → 0.1.7

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
2
  SHA256:
3
- metadata.gz: 47f23a09f7de2d295f934dfb79dcdfd9a4be86849678a21dcbec54c96d1c3d1e
4
- data.tar.gz: d18ffafed00d97d0d0cce364a9ff26785ae68940c53a08525db017e29f59d716
3
+ metadata.gz: 42d68d0dbbdfc96e269f94cc15383d7117613c807d4f7b73e108972c50a8dad2
4
+ data.tar.gz: c19f6dfecda00b7219a5f87b7b7bc6824dfa1d512ee4c2d3759c4020761c4df4
5
5
  SHA512:
6
- metadata.gz: 13488a433f342b2e78ce857afc3bd22c9c9d1c20d9306efe89a0c5bb0a4fa5a34ee3f17a57b7d476aa4d8dbb873dd4b35e97daf074ea8caed93eb10e6d63ed89
7
- data.tar.gz: e9cd4e696d86ccc714bf12b468acb1f0002d7c1107afc35c0d86b008e821d61151490b7b920b816302840b96c99886f86c432fcc481fb9917e2e0ae237edf988
6
+ metadata.gz: f75fbf53fb2eb1ee61ea47d504ab0b302b0544a40f2893b01a50d3acfde1a01bd2f5ddd14330e4572bfe96073ece9fc2e55924a2bd7295322906c8cec7079f6a
7
+ data.tar.gz: 22175c5e8695d51530003a58644fca0f4ead3b638b420bf2bee3dea6bfeff999aff9caaba2d780e8ceaf5cbfe7937aa7b1c2632e9b4a472b93e61d1bce5a3373
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,116 @@
1
+ require:
2
+ - rubocop-performance
3
+
4
+ AllCops:
5
+ TargetRubyVersion: 3.2
6
+ # RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
7
+ # to ignore them, so only the ones explicitly set in this file are enabled.
8
+ DisabledByDefault: true
9
+ Exclude:
10
+ - "**/vendor/**/*"
11
+ - "**/*_pb.rb"
12
+
13
+ # Prefer &&/|| over and/or.
14
+ Style/AndOr:
15
+ Enabled: true
16
+
17
+ Layout:
18
+ Enabled: false
19
+
20
+ # Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
21
+ Style/HashSyntax:
22
+ Enabled: true
23
+
24
+ Style/DefWithParentheses:
25
+ Enabled: true
26
+
27
+ # Defining a method with parameters needs parentheses.
28
+ Style/MethodDefParentheses:
29
+ Enabled: true
30
+
31
+ Style/FrozenStringLiteralComment:
32
+ Enabled: true
33
+ EnforcedStyle: always
34
+
35
+ Layout/EmptyLineAfterMagicComment:
36
+ Enabled: true
37
+
38
+ Style/RedundantFreeze:
39
+ Enabled: true
40
+
41
+ # Use quotes for string literals when they are enough.
42
+ Style/RedundantPercentQ:
43
+ Enabled: true
44
+
45
+ Style/StringLiterals:
46
+ Enabled: false
47
+
48
+ Lint/AmbiguousOperator:
49
+ Enabled: true
50
+
51
+ Lint/AmbiguousRegexpLiteral:
52
+ Enabled: true
53
+
54
+ Lint/ErbNewArguments:
55
+ Enabled: true
56
+
57
+ # Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
58
+ Lint/RequireParentheses:
59
+ Enabled: true
60
+
61
+ Lint/ShadowingOuterLocalVariable:
62
+ Enabled: true
63
+
64
+ Lint/RedundantStringCoercion:
65
+ Enabled: true
66
+
67
+ Lint/UriEscapeUnescape:
68
+ Enabled: true
69
+
70
+ Lint/UselessAssignment:
71
+ Enabled: true
72
+
73
+ Lint/DeprecatedClassMethods:
74
+ Enabled: true
75
+
76
+ Style/ParenthesesAroundCondition:
77
+ Enabled: true
78
+
79
+ Style/RedundantBegin:
80
+ Enabled: false
81
+
82
+ Style/RedundantReturn:
83
+ Enabled: true
84
+ AllowMultipleReturnValues: true
85
+
86
+ Style/Semicolon:
87
+ Enabled: true
88
+ AllowAsExpressionSeparator: true
89
+
90
+ # Prefer Foo.method over Foo::method
91
+ Style/ColonMethodCall:
92
+ Enabled: true
93
+
94
+ Style/TrivialAccessors:
95
+ Enabled: true
96
+
97
+ Performance/FlatMap:
98
+ Enabled: true
99
+
100
+ Performance/RedundantMerge:
101
+ Enabled: true
102
+
103
+ Performance/StartWith:
104
+ Enabled: true
105
+
106
+ Performance/EndWith:
107
+ Enabled: true
108
+
109
+ Performance/RegexpMatch:
110
+ Enabled: true
111
+
112
+ Performance/ReverseEach:
113
+ Enabled: true
114
+
115
+ Performance/UnfreezeString:
116
+ Enabled: true
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
data/gen_proto.sh ADDED
@@ -0,0 +1,9 @@
1
+ #!/bin/sh
2
+
3
+ find ../nuva -type f -name '*.proto' -exec basename {} \; | xargs protoc --ruby_out=./lib/nuva -I ../nuva
4
+
5
+ if [ `uname` = 'Darwin' ]; then
6
+ sed -i '' -E "s/^require '([a-zA-Z_]+)'/require_relative '\1'/" ./lib/nuva/*_pb.rb
7
+ else
8
+ sed -i -E "s/^require '([a-zA-Z_]+)'/require_relative '\1'/" ./lib/nuva/*_pb.rb
9
+ fi
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'fuzzy_match'
2
4
 
3
5
  module Nuva
4
6
  module Queries
5
7
  class ValencesByVaccine
6
8
  def initialize(repositories)
7
- h = Hash.new { |h, k| h[k] = [] }
8
- @valences_by_vaccine_id = repositories[:valences].all.reduce(h) do |acc, valence|
9
+ hash = Hash.new { |h, k| h[k] = [] }
10
+ @valences_by_vaccine_id = repositories[:valences].all.reduce(hash) do |acc, valence|
9
11
  valence.vaccine_ids.each do |vaccine_id|
10
12
  acc[vaccine_id] << valence
11
13
  end
@@ -20,8 +22,8 @@ module Nuva
20
22
 
21
23
  class VaccinesByValence
22
24
  def initialize(repositories)
23
- h = Hash.new { |h, k| h[k] = [] }
24
- @vaccines_by_valence_id = repositories[:vaccines].all.reduce(h) do |acc, vaccine|
25
+ hash = Hash.new { |h, k| h[k] = [] }
26
+ @vaccines_by_valence_id = repositories[:vaccines].all.reduce(hash) do |acc, vaccine|
25
27
  vaccine.valence_ids.each do |valence_id|
26
28
  acc[valence_id] << vaccine
27
29
  end
@@ -36,8 +38,8 @@ module Nuva
36
38
 
37
39
  class VaccinesByDisease
38
40
  def initialize(repositories)
39
- h = Hash.new { |h, k| h[k] = [] }
40
- @vaccines_by_disease_id = repositories[:valences].all.reduce(h) do |acc, valence|
41
+ hash = Hash.new { |h, k| h[k] = [] }
42
+ @vaccines_by_disease_id = repositories[:valences].all.reduce(hash) do |acc, valence|
41
43
  valence.disease_ids.each do |disease_id|
42
44
  valence.vaccine_ids.each do |vaccine_id|
43
45
  acc[disease_id] << repositories[:vaccines].find(vaccine_id)
@@ -48,14 +50,14 @@ module Nuva
48
50
  end
49
51
 
50
52
  def call(disease)
51
- @vaccines_by_disease_id[disease.id]
53
+ @vaccines_by_disease_id[disease.id].uniq(&:id)
52
54
  end
53
55
  end
54
56
 
55
57
  class ValencesByDisease
56
58
  def initialize(repositories)
57
- h = Hash.new { |h, k| h[k] = [] }
58
- @valences_by_disease_id = repositories[:valences].all.reduce(h) do |acc, valence|
59
+ hash = Hash.new { |h, k| h[k] = [] }
60
+ @valences_by_disease_id = repositories[:valences].all.reduce(hash) do |acc, valence|
59
61
  valence.disease_ids.each do |disease_id|
60
62
  acc[disease_id] << valence
61
63
  end
@@ -70,8 +72,8 @@ module Nuva
70
72
 
71
73
  class DiseasesByVaccine
72
74
  def initialize(repositories)
73
- h = Hash.new { |h, k| h[k] = [] }
74
- @diseases_by_vaccine_id = repositories[:valences].all.reduce(h) do |acc, valence|
75
+ hash = Hash.new { |h, k| h[k] = [] }
76
+ @diseases_by_vaccine_id = repositories[:valences].all.reduce(hash) do |acc, valence|
75
77
  valence.vaccine_ids.each do |vaccine_id|
76
78
  valence.disease_ids.each do |disease_id|
77
79
  acc[vaccine_id] << repositories[:diseases].find(disease_id)
@@ -82,14 +84,14 @@ module Nuva
82
84
  end
83
85
 
84
86
  def call(vaccine)
85
- @diseases_by_vaccine_id[vaccine.id]
87
+ @diseases_by_vaccine_id[vaccine.id].uniq(&:id)
86
88
  end
87
89
  end
88
90
 
89
91
  class DiseasesByValence
90
92
  def initialize(repositories)
91
- h = Hash.new { |h, k| h[k] = [] }
92
- @diseases_by_valence_id = repositories[:diseases].all.reduce(h) do |acc, disease|
93
+ hash = Hash.new { |h, k| h[k] = [] }
94
+ @diseases_by_valence_id = repositories[:diseases].all.reduce(hash) do |acc, disease|
93
95
  disease.valence_ids.each do |valence_id|
94
96
  acc[valence_id] << disease
95
97
  end
@@ -104,8 +106,8 @@ module Nuva
104
106
 
105
107
  class VaccineFuzzySearch
106
108
  def initialize(repositories)
107
- @engine = FuzzyMatch.new(repositories.vaccines.all, :read => ->(v) {
108
- return v.name
109
+ @engine = FuzzyMatch.new(repositories.vaccines.all, read: ->(v) {
110
+ v.name
109
111
  })
110
112
  end
111
113
 
@@ -148,7 +150,7 @@ module Nuva
148
150
  end
149
151
  end
150
152
 
151
- class LookupSpecializedVaccines
153
+ class LookupGeneralizedVaccines
152
154
  def initialize(repositories, valencesByVaccine)
153
155
  @vaccines = repositories.vaccines
154
156
  @valences = repositories.valences
@@ -158,56 +160,28 @@ module Nuva
158
160
  def call(vaccine)
159
161
  targetValences = @valencesByVaccine.(vaccine)
160
162
  list = @vaccines.all.filter do |candidate|
161
- candidate.id != vaccine.id && targetValences.all? do |targetValence|
162
- @valencesByVaccine.(candidate).any? do |candidateValence|
163
- child_of? candidateValence, targetValence
163
+ next if candidate.id == vaccine.id || !candidate.generic
164
+
165
+ @valencesByVaccine.(candidate).all? do |candidateValence|
166
+ targetValences.any? do |targetValence|
167
+ parent_of?(candidateValence, targetValence)
164
168
  end
165
169
  end
166
170
  end
167
- list.sort_by do |v| @valencesByVaccine.(v).length end
171
+ list.sort_by do |v| -@valencesByVaccine.(v).length end
168
172
  end
169
173
 
170
174
  private def child_of?(valence, parent)
171
- unless valence.nil?
175
+ until valence.nil?
172
176
  return true if valence.id == parent.id
173
- valence = @valences.find valence.parent_id
177
+ valence = @valences.find(valence.parent_id)
174
178
  end
175
179
 
176
180
  false
177
181
  end
178
- end
179
-
180
182
 
181
- class LookupGeneralizedVaccines
182
- def initialize(repositories, valencesByVaccine)
183
- @vaccines = repositories.vaccines
184
- @valences = repositories.valences
185
- @valencesByVaccine = valencesByVaccine
186
- end
187
-
188
- def call(vaccine)
189
- targetValences = @valencesByVaccine.(vaccine)
190
- list = @vaccines.all.filter do |candidate|
191
- candidate.id != vaccine.id && targetValences.all? do |targetValence|
192
- @valencesByVaccine.(candidate).any? do |candidateValence|
193
- child_of? candidateValence, targetValence
194
- end
195
- end
196
- end
197
- list.sort_by do |v| @valencesByVaccine.(v).length end
198
- end
199
-
200
- private def parent_of?(valence, parent)
201
- child_of? parent, valence
202
- end
203
-
204
- private def child_of?(valence, parent)
205
- unless valence.nil?
206
- return true if valence.id == parent.id
207
- valence = @valences.find valence.parent_id
208
- end
209
-
210
- false
183
+ def parent_of?(parent, child)
184
+ child_of?(child, parent)
211
185
  end
212
186
  end
213
187
 
@@ -228,7 +202,7 @@ module Nuva
228
202
  @vaccines = repositories.vaccines
229
203
  end
230
204
 
231
- def call()
205
+ def call
232
206
  @vaccines
233
207
  .all
234
208
  .flat_map(&:codes)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nuva
2
4
  class DiseaseRepository < Repository
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nuva
2
4
  class VaccineRepository < Repository
3
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module Nuva
3
4
  class ValenceRepository < Repository
4
5
  def initialize(data)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Nuva
2
4
  class Repository
3
5
  attr_reader :data
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Nuva
4
+ VERSION = '0.1.7'
5
+ end
data/lib/nuva.rb CHANGED
@@ -1,7 +1,9 @@
1
- require_relative './version'
2
- require_relative './NuvaDatabase_pb'
3
- require_relative './repository'
4
- require_relative './queries'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'nuva/version'
4
+ require_relative 'nuva/NuvaDatabase_pb'
5
+ require_relative 'nuva/repository'
6
+ require_relative 'nuva/queries'
5
7
  require 'net/http'
6
8
  require 'json'
7
9
  require 'ostruct'
@@ -30,18 +32,21 @@ module Nuva
30
32
  @queries.vaccine_fuzzy_search = ::Nuva::Queries::VaccineFuzzySearch.new @repositories
31
33
  @queries.lookup_vaccine_by_code = ::Nuva::Queries::LookupVaccineByCode.new @repositories
32
34
  @queries.lookup_equivalent_vaccines = ::Nuva::Queries::LookupEquivalentVaccines.new @repositories
33
- @queries.lookup_specialized_vaccines = ::Nuva::Queries::LookupSpecializedVaccines.new @repositories, @queries.valences_by_vaccine
34
35
  @queries.lookup_generalized_vaccines = ::Nuva::Queries::LookupGeneralizedVaccines.new @repositories, @queries.valences_by_vaccine
35
36
  @queries.all_nomenclatures = ::Nuva::Queries::AllNomenclatures.new @repositories
36
37
  @queries.all_code_by_nomenclature = ::Nuva::Queries::AllCodeByNomenclature.new @repositories
37
38
  @queries.freeze
38
39
  end
39
40
 
41
+ def version
42
+ @db.version
43
+ end
44
+
40
45
  def self.load(lang = "en")
41
46
  latest_version_uri = URI "https://cdnnuva.mesvaccins.net/versions/last.json"
42
47
 
43
48
  ::Net::HTTP.start(latest_version_uri.host, latest_version_uri.port,
44
- :use_ssl => latest_version_uri.scheme == 'https') do |http|
49
+ use_ssl: latest_version_uri.scheme == 'https') do |http|
45
50
 
46
51
  # Fetch version manifest
47
52
  req = ::Net::HTTP::Get.new latest_version_uri
@@ -49,7 +54,7 @@ module Nuva
49
54
  res = http.request req
50
55
  res.value
51
56
 
52
- manifest = JSON::parse(res.body)
57
+ manifest = JSON.parse(res.body)
53
58
 
54
59
  dump_hash = manifest['dump_hash']
55
60
 
data/nuva.gemspec CHANGED
@@ -1,16 +1,37 @@
1
- require_relative "lib/version"
1
+ # frozen_string_literal: true
2
2
 
3
- Gem::Specification.new do |s|
4
- s.name = 'nuva'
5
- s.version = Nuva::VERSION
6
- s.licenses = ['MIT']
7
- s.summary = "NUVA"
8
- s.description = "nuva library aims to simplify working and interacting with the NUVA nomenclature through queries and repositories"
9
- s.authors = ["Syadem"]
10
- s.email = ''
11
- s.files = Dir.chdir(File.expand_path(__dir__)) {
12
- `find . -type f -name '*.rb' -print0`.split("\0").concat %w[nuva.gemspec]
13
- }
14
- s.add_dependency 'google-protobuf', '~> 3.25', '>= 3.25.3'
15
- s.add_dependency 'fuzzy_match', '~> 2.1'
3
+ require_relative "lib/nuva/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "nuva"
7
+ spec.version = Nuva::VERSION
8
+ spec.authors = ["Syadem"]
9
+ spec.email = ["developers@mesvaccins.net"]
10
+
11
+ spec.summary = "NUVA"
12
+ spec.description = "nuva library aims to simplify working and interacting with the NUVA nomenclature through queries and repositories."
13
+ spec.homepage = "https://docs.nuva.mesvaccins.net"
14
+ spec.required_ruby_version = ">= 3.0.0"
15
+
16
+ spec.metadata["homepage_uri"] = spec.homepage
17
+ # spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
18
+ # spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
19
+
20
+ # Specify which files should be added to the gem when it is released.
21
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
22
+ spec.files = Dir.chdir(__dir__) do
23
+ `git ls-files -z`.split("\x0").reject do |f|
24
+ (File.expand_path(f) == __FILE__) ||
25
+ f.start_with?(*%w[bin/ test/ spec/ features/ .git .gitlab-ci.yml appveyor Gemfile])
26
+ end
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_dependency 'google-protobuf', '~> 3.25', '>= 3.25.3'
33
+ spec.add_dependency 'fuzzy_match', '~> 2.1'
34
+
35
+ # For more information and examples about making a new gem, check out our
36
+ # guide at: https://bundler.io/guides/creating_gem.html
16
37
  end
data/sig/nuva.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module Nuva
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nuva
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Syadem
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2024-03-26 00:00:00.000000000 Z
11
+ date: 2024-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: google-protobuf
@@ -45,31 +45,37 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '2.1'
47
47
  description: nuva library aims to simplify working and interacting with the NUVA nomenclature
48
- through queries and repositories
49
- email: ''
48
+ through queries and repositories.
49
+ email:
50
+ - developers@mesvaccins.net
50
51
  executables: []
51
52
  extensions: []
52
53
  extra_rdoc_files: []
53
54
  files:
54
- - "./lib/Code_pb.rb"
55
- - "./lib/Disease_pb.rb"
56
- - "./lib/InjectionMethod_pb.rb"
57
- - "./lib/NuvaDatabase_pb.rb"
58
- - "./lib/Vaccine_pb.rb"
59
- - "./lib/Valence_pb.rb"
60
- - "./lib/VersionInfo_pb.rb"
61
- - "./lib/nuva.rb"
62
- - "./lib/queries.rb"
63
- - "./lib/repositories/disease_repository.rb"
64
- - "./lib/repositories/vaccine_repository.rb"
65
- - "./lib/repositories/valence_repository.rb"
66
- - "./lib/repository.rb"
67
- - "./lib/version.rb"
55
+ - ".rspec"
56
+ - ".rubocop.yml"
57
+ - Rakefile
58
+ - gen_proto.sh
59
+ - lib/nuva.rb
60
+ - lib/nuva/Code_pb.rb
61
+ - lib/nuva/Disease_pb.rb
62
+ - lib/nuva/InjectionMethod_pb.rb
63
+ - lib/nuva/NuvaDatabase_pb.rb
64
+ - lib/nuva/Vaccine_pb.rb
65
+ - lib/nuva/Valence_pb.rb
66
+ - lib/nuva/VersionInfo_pb.rb
67
+ - lib/nuva/queries.rb
68
+ - lib/nuva/repositories/disease_repository.rb
69
+ - lib/nuva/repositories/vaccine_repository.rb
70
+ - lib/nuva/repositories/valence_repository.rb
71
+ - lib/nuva/repository.rb
72
+ - lib/nuva/version.rb
68
73
  - nuva.gemspec
69
- homepage:
70
- licenses:
71
- - MIT
72
- metadata: {}
74
+ - sig/nuva.rbs
75
+ homepage: https://docs.nuva.mesvaccins.net
76
+ licenses: []
77
+ metadata:
78
+ homepage_uri: https://docs.nuva.mesvaccins.net
73
79
  post_install_message:
74
80
  rdoc_options: []
75
81
  require_paths:
@@ -78,7 +84,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
84
  requirements:
79
85
  - - ">="
80
86
  - !ruby/object:Gem::Version
81
- version: '0'
87
+ version: 3.0.0
82
88
  required_rubygems_version: !ruby/object:Gem::Requirement
83
89
  requirements:
84
90
  - - ">="
data/lib/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module Nuva
2
- VERSION = '0.1.6'
3
- end
File without changes
File without changes
File without changes
File without changes
File without changes