class Sommelier::MatchMaker::Generator

Generate all of the requested pairings for a single round of the algorithm. Each dish that isn't currently locked in a pairing from a prior round and hasn't exhausted its list of preferred wines will request a pairing with the highest matching wine it has not yet requested.

Attributes

match_catalog[R]

Public Class Methods

new(match_catalog) click to toggle source
# File lib/sommelier/match_maker/generator.rb, line 9
def initialize(match_catalog)
  @match_catalog = match_catalog
end

Public Instance Methods

requests(round, accepted) click to toggle source

@param round [Integer] the round number @param accepted [Hash<Object, Object>] mapping of dishes to the wine

that has accepted his pairing

@return [Hash<Object, Array<Object>>] mapping of wines to the list of

dishes that have requested pairings in the current round
# File lib/sommelier/match_maker/generator.rb, line 18
def requests(round, accepted)
  requests = {}
  match_catalog.each_dish do |dish, preferences_count|
    if round < preferences_count && !accepted.key?(dish)
      wine = match_catalog.wine_preferred_at(dish, round)
      requests[wine] ||= []
      requests[wine] << dish
    end
  end
  requests
end