Class: Nuva::Queries::VaccinesByValence

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

Instance Method Summary collapse

Constructor Details

#initialize(repositories) ⇒ VaccinesByValence

Returns a new instance of VaccinesByValence.



24
25
26
27
28
29
30
31
32
# File 'lib/nuva/queries.rb', line 24

def initialize(repositories)
  hash = Hash.new { |h, k| h[k] = [] }
  @vaccines_by_valence_id = repositories[:vaccines].all.reduce(hash) do |acc, vaccine|
    vaccine.valence_ids.each do |valence_id|
      acc[valence_id] << vaccine
    end
    acc
  end
end

Instance Method Details

#call(valence) ⇒ Object



34
35
36
# File 'lib/nuva/queries.rb', line 34

def call(valence)
  @vaccines_by_valence_id[valence.id]
end