Class: Nuva::Nuva
- Inherits:
-
Object
- Object
- Nuva::Nuva
- Defined in:
- lib/nuva.rb
Instance Attribute Summary collapse
-
#queries ⇒ Object
readonly
Returns the value of attribute queries.
-
#repositories ⇒ Object
readonly
Returns the value of attribute repositories.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(db) ⇒ Nuva
constructor
A new instance of Nuva.
- #version ⇒ Object
Constructor Details
#initialize(db) ⇒ Nuva
Returns a new instance of Nuva.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/nuva.rb', line 16 def initialize(db) @db = db @repositories = OpenStruct.new @repositories.vaccines = VaccineRepository.new db.vaccines @repositories.valences = ValenceRepository.new db.valences @repositories.diseases = DiseaseRepository.new db.diseases @repositories.freeze @queries = OpenStruct.new @queries.valences_by_vaccine = ::Nuva::Queries::ValencesByVaccine.new @repositories @queries.vaccines_by_valence = ::Nuva::Queries::VaccinesByValence.new @repositories @queries.vaccines_by_disease = ::Nuva::Queries::VaccinesByDisease.new @repositories @queries.valences_by_disease = ::Nuva::Queries::ValencesByDisease.new @repositories @queries.diseases_by_vaccine = ::Nuva::Queries::DiseasesByVaccine.new @repositories @queries.diseases_by_valence = ::Nuva::Queries::DiseasesByValence.new @repositories @queries.vaccine_fuzzy_search = ::Nuva::Queries::VaccineFuzzySearch.new @repositories @queries.lookup_vaccine_by_code = ::Nuva::Queries::LookupVaccineByCode.new @repositories @queries.lookup_equivalent_vaccines = ::Nuva::Queries::LookupEquivalentVaccines.new @repositories @queries.lookup_generalized_vaccines = ::Nuva::Queries::LookupGeneralizedVaccines.new @repositories, @queries.valences_by_vaccine @queries.all_nomenclatures = ::Nuva::Queries::AllNomenclatures.new @repositories @queries.all_code_by_nomenclature = ::Nuva::Queries::AllCodeByNomenclature.new @repositories @queries.freeze end |
Instance Attribute Details
#queries ⇒ Object (readonly)
Returns the value of attribute queries.
14 15 16 |
# File 'lib/nuva.rb', line 14 def queries @queries end |
#repositories ⇒ Object (readonly)
Returns the value of attribute repositories.
13 14 15 |
# File 'lib/nuva.rb', line 13 def repositories @repositories end |
Class Method Details
.load(lang = "en") ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/nuva.rb', line 45 def self.load(lang = "en") latest_version_uri = URI "https://cdnnuva.mesvaccins.net/versions/last.json" ::Net::HTTP.start(latest_version_uri.host, latest_version_uri.port, use_ssl: latest_version_uri.scheme == 'https') do |http| # Fetch version manifest req = ::Net::HTTP::Get.new latest_version_uri res = http.request req res.value manifest = JSON.parse(res.body) dump_hash = manifest['dump_hash'] # Fetch latest database dump_uri = latest_version_uri.dup dump_uri.path = "/proto/#{dump_hash}_#{lang}.db" req = ::Net::HTTP::Get.new dump_uri res = http.request req res.value # The return value of the block is returned by the start method ::Nuva::Nuva.new(::Nuva::NuvaDatabase.decode(res.body)) end end |
.load_from_file(path) ⇒ Object
76 77 78 |
# File 'lib/nuva.rb', line 76 def self.load_from_file(path) Nuva.new(NuvaDatabase.decode(File.read(path))) end |
Instance Method Details
#version ⇒ Object
41 42 43 |
# File 'lib/nuva.rb', line 41 def version @db.version end |