Module: SciolyFF::Interpreter::Bids

Included in:
Tournament
Defined in:
lib/sciolyff/interpreter/bids.rb

Overview

Bid assignment logic, to be included in the Interpreter::Tournament class

Instance Method Summary collapse

Instance Method Details

#teams_eligible_for_bidsObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sciolyff/interpreter/bids.rb', line 11

def teams_eligible_for_bids
  return top_teams_per_school if bids_per_school == 1

  # doesn't rely on group_by preserving order
  @teams_eligible_for_bids ||=
    @teams
    .group_by { |t| [t.school, t.city, t.state] }
    .each_value { |teams| teams.sort_by!(&:rank) }
    .map { |_, teams| teams.take(bids_per_school) }
    .flatten
    .sort_by(&:rank)
end

#top_teams_per_schoolObject



6
7
8
9
# File 'lib/sciolyff/interpreter/bids.rb', line 6

def top_teams_per_school
  # explicitly relies on uniq traversing in order
  @top_teams_per_school ||= @teams.uniq { |t| [t.school, t.city, t.state] }
end