Destroying all Readability.

Noone will ever be able to read this code again.
This commit is contained in:
Daniel Schädler 2019-05-04 20:54:08 +02:00
parent 23249ee93b
commit f7ed4b549d
1 changed files with 5 additions and 6 deletions

View File

@ -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: [