diff --git a/app/services/group_stage_service.rb b/app/services/group_stage_service.rb index 0c2b7d7..ea03168 100644 --- a/app/services/group_stage_service.rb +++ b/app/services/group_stage_service.rb @@ -4,22 +4,21 @@ class GroupStageService def self.generate_group_stage(groups) raise 'Cannot generate group stage without groups' if groups.length.zero? - average_group_size = (groups.flatten.length.to_f / groups.length.to_f) - raise 'Groups need to be equal size' unless (average_group_size % 1).zero? + # raise an error if the average group size is not a whole number + raise 'Groups need to be equal size' unless (groups.flatten.length.to_f / groups.length.to_f % 1).zero? groups = groups.map(&method(:get_group_object_from)) Stage.new level: -1, groups: groups end def self.get_group_object_from(team_array) - matches = generate_all_matches_between team_array - Group.new matches: matches + Group.new matches: generate_all_matches_between(team_array) end def self.generate_all_matches_between(teams) matches = [] - matchups = teams.combination(2).to_a - matchups.each_with_index do |matchup, i| + teams.combination(2).to_a # = matchups + .each_with_index do |matchup, i| match = Match.new state: :not_started, position: i, match_scores: [