Move self methods into self block
This commit is contained in:
parent
3ace826180
commit
e222669321
|
|
@ -1,32 +1,34 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
class GroupStageService
|
class GroupStageService
|
||||||
def self.generate_group_stage(groups)
|
class << self
|
||||||
raise 'Cannot generate group stage without groups' if groups.length.zero?
|
def generate_group_stage(groups)
|
||||||
|
raise 'Cannot generate group stage without groups' if groups.length.zero?
|
||||||
|
|
||||||
# raise an error if the average group size is not a whole number
|
# 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?
|
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 get_group_object_from(team_array)
|
||||||
Group.new matches: generate_all_matches_between(team_array)
|
Group.new matches: generate_all_matches_between(team_array)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.generate_all_matches_between(teams)
|
def generate_all_matches_between(teams)
|
||||||
matches = []
|
matches = []
|
||||||
teams.combination(2).to_a # = matchups
|
teams.combination(2).to_a # = 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: [
|
||||||
MatchScore.new(team: matchup.first),
|
MatchScore.new(team: matchup.first),
|
||||||
MatchScore.new(team: matchup.second)
|
MatchScore.new(team: matchup.second)
|
||||||
]
|
]
|
||||||
matches << match
|
matches << match
|
||||||
|
end
|
||||||
|
matches
|
||||||
end
|
end
|
||||||
matches
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue