Class: Nuva::Queries::AllCodeByNomenclatureQuery

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

Instance Method Summary collapse

Methods inherited from Query

#inspect

Constructor Details

#initialize(repositories) ⇒ AllCodeByNomenclatureQuery

Returns a new instance of AllCodeByNomenclatureQuery.



217
218
219
# File 'lib/nuva/queries.rb', line 217

def initialize(repositories)
  @vaccines = repositories.vaccines
end

Instance Method Details

#callObject



221
222
223
224
225
226
227
228
229
230
231
# File 'lib/nuva/queries.rb', line 221

def call
  @vaccines
    .all
    .flat_map(&:codes)
    .reduce(Hash.new { |hash, key| hash[key] = [] }) do |hash, code|
      hash[code.nomenclature] << code.value
      hash
    end
    .map { |key, value| [key, value.uniq] }
    .to_h
end