From e2226693211bdfdcdaca95e8c8d1e700e4e636f6 Mon Sep 17 00:00:00 2001 From: Malaber <32635600+Malaber@users.noreply.github.com> Date: Fri, 10 May 2019 11:34:01 +0200 Subject: [PATCH] Move self methods into self block --- app/services/group_stage_service.rb | 50 +++++++++++++++-------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/app/services/group_stage_service.rb b/app/services/group_stage_service.rb index ea03168..bdd18d9 100644 --- a/app/services/group_stage_service.rb +++ b/app/services/group_stage_service.rb @@ -1,32 +1,34 @@ # frozen_string_literal: true class GroupStageService - def self.generate_group_stage(groups) - raise 'Cannot generate group stage without groups' if groups.length.zero? + class << self + 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 'Groups need to be equal size' unless (groups.flatten.length.to_f / groups.length.to_f % 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) - Group.new matches: generate_all_matches_between(team_array) - end - - def self.generate_all_matches_between(teams) - matches = [] - teams.combination(2).to_a # = matchups - .each_with_index do |matchup, i| - match = Match.new state: :not_started, - position: i, - match_scores: [ - MatchScore.new(team: matchup.first), - MatchScore.new(team: matchup.second) - ] - matches << match + groups = groups.map(&method(:get_group_object_from)) + Stage.new level: -1, groups: groups + end + + def get_group_object_from(team_array) + Group.new matches: generate_all_matches_between(team_array) + end + + def generate_all_matches_between(teams) + matches = [] + teams.combination(2).to_a # = matchups + .each_with_index do |matchup, i| + match = Match.new state: :not_started, + position: i, + match_scores: [ + MatchScore.new(team: matchup.first), + MatchScore.new(team: matchup.second) + ] + matches << match + end + matches end - matches end end