Class: Nuva::Queries::ValencesByVaccineQuery

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

Instance Method Summary collapse

Methods inherited from Query

#inspect

Constructor Details

#initialize(repositories) ⇒ ValencesByVaccineQuery



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/nuva/queries.rb', line 14

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

Instance Method Details

#call(vaccine) ⇒ Object



27
28
29
# File 'lib/nuva/queries.rb', line 27

def call(vaccine)
  @valences_by_vaccine_id[vaccine.id]
end