Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Update seed data for games.

  • Loading branch information...
commit 66d579d0ba36f274b6f6a736040f29d659e44b81 1 parent ed09b10
Alex Burkhart authored April 19, 2012

Showing 1 changed file with 15 additions and 1 deletion. Show diff stats Hide diff stats

  1. 16  db/seeds.rb
16  db/seeds.rb
@@ -17,13 +17,27 @@
17 17
              Player.create(name: "Peggy")
18 18
            ]
19 19
 
  20
+def rand_game(match, player_one, player_two)
  21
+  w = 11
  22
+  l = 11 - (rand(5) + 1)
  23
+  if rand > 0.75
  24
+    match.games.build(winner: player_one, winner_score: w,
  25
+                      loser:  player_two,  loser_score: l)
  26
+  else
  27
+    match.games.build(winner: player_two, winner_score: w,
  28
+                      loser:  player_one,  loser_score: l)
  29
+  end
  30
+end
  31
+
20 32
 def rand_match(time)
21 33
   player_one = @players[rand(@players.size)]
22 34
   player_two = @players[rand(@players.size)]
23 35
   while player_one == player_two 
24 36
     player_two = @players[rand(@players.size)]
25 37
   end
26  
-  Match.create(winner: player_one, loser: player_two, occured_at: time)
  38
+  match = Match.new(winner_score: 0, loser_score: 0, occured_at: time)
  39
+  3.times { |i| rand_game(match, player_one, player_two) }
  40
+  match.save!
27 41
 end
28 42
 
29 43
 # Make up two weeks worth of matches to play around with.

0 notes on commit 66d579d

Please sign in to comment.
Something went wrong with that request. Please try again.