Class: Nuva::Queries::DiseasesByVaccine

Inherits:
Object
  • Object
show all
Defined in:
lib/nuva/queries.rb

Instance Method Summary collapse

Constructor Details

#initialize(repositories) ⇒ DiseasesByVaccine

Returns a new instance of DiseasesByVaccine.



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/nuva/queries.rb', line 74

def initialize(repositories)
  hash = Hash.new { |h, k| h[k] = [] }
  @diseases_by_vaccine_id = repositories[:valences].all.reduce(hash) do |acc, valence|
    valence.vaccine_ids.each do |vaccine_id|
      valence.disease_ids.each do |disease_id|
        acc[vaccine_id] << repositories[:diseases].find(disease_id)
      end
    end
    acc
  end
end

Instance Method Details

#call(vaccine) ⇒ Object



86
87
88
# File 'lib/nuva/queries.rb', line 86

def call(vaccine)
  @diseases_by_vaccine_id[vaccine.id].uniq(&:id)
end