Class: Nuva::Queries::VaccinesByDisease
- Inherits:
-
Object
- Object
- Nuva::Queries::VaccinesByDisease
- Defined in:
- lib/nuva/queries.rb
Instance Method Summary collapse
- #call(disease) ⇒ Object
-
#initialize(repositories) ⇒ VaccinesByDisease
constructor
A new instance of VaccinesByDisease.
Constructor Details
#initialize(repositories) ⇒ VaccinesByDisease
Returns a new instance of VaccinesByDisease.
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/nuva/queries.rb', line 40 def initialize(repositories) hash = Hash.new { |h, k| h[k] = [] } @vaccines_by_disease_id = repositories[:valences].all.reduce(hash) do |acc, valence| valence.disease_ids.each do |disease_id| valence.vaccine_ids.each do |vaccine_id| acc[disease_id] << repositories[:vaccines].find(vaccine_id) end end acc end end |
Instance Method Details
#call(disease) ⇒ Object
52 53 54 |
# File 'lib/nuva/queries.rb', line 52 def call(disease) @vaccines_by_disease_id[disease.id].uniq(&:id) end |