Class: Nuva::Queries::LookupGeneralizedVaccines

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

Instance Method Summary collapse

Constructor Details

#initialize(repositories, valencesByVaccine) ⇒ LookupGeneralizedVaccines

Returns a new instance of LookupGeneralizedVaccines.



154
155
156
157
158
# File 'lib/nuva/queries.rb', line 154

def initialize(repositories, valencesByVaccine)
  @vaccines = repositories.vaccines
  @valences = repositories.valences
  @valencesByVaccine = valencesByVaccine
end

Instance Method Details

#call(vaccine) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/nuva/queries.rb', line 160

def call(vaccine)
  targetValences = @valencesByVaccine.(vaccine)
  list = @vaccines.all.filter do |candidate|
    next if candidate.id == vaccine.id || !candidate.generic
    
    @valencesByVaccine.(candidate).all? do |candidateValence|
      targetValences.any? do |targetValence|
        parent_of?(candidateValence, targetValence)
      end
    end
  end
  list.sort_by do |v| -@valencesByVaccine.(v).length end
end

#parent_of?(parent, child) ⇒ Boolean

Returns:

  • (Boolean)


183
184
185
# File 'lib/nuva/queries.rb', line 183

def parent_of?(parent, child)
  child_of?(child, parent)
end