diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/pages_controller.rb | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/app/controllers/pages_controller.rb b/app/controllers/pages_controller.rb index e3838d2..2c454f9 100644 --- a/app/controllers/pages_controller.rb +++ b/app/controllers/pages_controller.rb @@ -5,31 +5,29 @@ class PagesController < ApplicationController def teampicker @groups = maketeams + + @machines = Machine.limit(@groups.count).order(Arel.sql("RANDOM()")) end private - def random - Player.where("strikes < 4").order(Arel.sql("RANDOM()")) - end - def maketeams - r = random.to_a + r = Player.where("strikes < 4").order(Arel.sql("RANDOM()")).to_a - case Player.count { |p| p.active? } - when 5 - [r.shift(3), r.shift(2)] - when 6 - r.each_slice(3) - when 9 - r.each_slice(3) - when 10 - [r.shift(4), r.shift(3), r.shift(3)] - when 13 - [r.shift(4), r.shift(3), r.shift(3), r.shift(3)] - when 14 - [r.shift(4), r.shift(4), r.shift(3), r.shift(3)] - else - r.each_slice(4) - end + groups = case r.count + when 5 + [r.shift(3), r.shift(2)] + when 6 + r.each_slice(3) + when 9 + r.each_slice(3) + when 10 + [r.shift(4), r.shift(3), r.shift(3)] + when 13 + [r.shift(4), r.shift(3), r.shift(3), r.shift(3)] + when 14 + [r.shift(4), r.shift(4), r.shift(3), r.shift(3)] + else + r.each_slice(4) + end end end |