Destroying all Readability.
Noone will ever be able to read this code again.
This commit is contained in:
parent
23249ee93b
commit
f7ed4b549d
|
|
@ -4,22 +4,21 @@ class GroupStageService
|
||||||
def self.generate_group_stage(groups)
|
def self.generate_group_stage(groups)
|
||||||
raise 'Cannot generate group stage without groups' if groups.length.zero?
|
raise 'Cannot generate group stage without groups' if groups.length.zero?
|
||||||
|
|
||||||
average_group_size = (groups.flatten.length.to_f / groups.length.to_f)
|
# raise an error if the average group size is not a whole number
|
||||||
raise 'Groups need to be equal size' unless (average_group_size % 1).zero?
|
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))
|
groups = groups.map(&method(:get_group_object_from))
|
||||||
Stage.new level: -1, groups: groups
|
Stage.new level: -1, groups: groups
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get_group_object_from(team_array)
|
def self.get_group_object_from(team_array)
|
||||||
matches = generate_all_matches_between team_array
|
Group.new matches: generate_all_matches_between(team_array)
|
||||||
Group.new matches: matches
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.generate_all_matches_between(teams)
|
def self.generate_all_matches_between(teams)
|
||||||
matches = []
|
matches = []
|
||||||
matchups = teams.combination(2).to_a
|
teams.combination(2).to_a # = matchups
|
||||||
matchups.each_with_index do |matchup, i|
|
.each_with_index do |matchup, i|
|
||||||
match = Match.new state: :not_started,
|
match = Match.new state: :not_started,
|
||||||
position: i,
|
position: i,
|
||||||
match_scores: [
|
match_scores: [
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue