Sha256: 7b4a342f2821394c9b304cbdcd5e589dba84fe4d9f862cb4bf75cb8d971b27dd

Contents?: true

Size: 650 Bytes

Versions: 2

Compression:

Stored size: 650 Bytes

Contents

module Nuva
  class Repository
    attr_reader :data

    def initialize(data)
      @data = index_array_by_id(data)
    end

    def find(id)
      @data[id]
    end

    def all
      @data.values
    end

    def by_ids(ids)
      ids.map { |x| find x }.compact
    end

    # def by_ids(ids)
      # @data.select { |k, _v| ids.include?(k) }.values
    # end

    private

    def index_array_by_id(array)
      array.each_with_object({}) { |item, acc| acc[item.id] = item }
    end
  end
end

require_relative 'repositories/disease_repository'
require_relative 'repositories/vaccine_repository'
require_relative 'repositories/valence_repository'

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
nuva-0.1.6 ./lib/repository.rb
nuva-0.1.5 ./lib/repository.rb