-
Notifications
You must be signed in to change notification settings - Fork 0
/
match.rb
82 lines (81 loc) · 2.67 KB
/
match.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class Match < ActiveRecord::Base
belongs_to :babyface, class_name: 'Wrestler'
belongs_to :heel, class_name: 'Wrestler'
belongs_to :card
def self.set_match(position, id, num_matches)
index = 0
matches = []
if position == 5
@main_event_babyfaces = Wrestler.set_main_event_babyfaces(id, false).to_a
@main_event_heels = Wrestler.set_main_event_heels(id, false).to_a
while index < num_matches
match = Match.new
@main_event_heels.shuffle!
match.heel = @main_event_heels.pop
@main_event_babyfaces.shuffle!
match.babyface = @main_event_babyfaces.pop
match.position = position
match.save
matches << match
index += 1
end
elsif position == 4
@high_card_babyfaces = Wrestler.set_high_card_babyfaces(id, false).to_a
@high_card_heels = Wrestler.set_high_card_heels(id, false).to_a
while index < num_matches
match = Match.new
@high_card_heels.shuffle!
match.heel = @high_card_heels.pop
@high_card_babyfaces.shuffle!
match.babyface = @high_card_babyfaces.pop
match.position = position
match.save
matches << match
index += 1
end
elsif position == 3
@mid_card_babyfaces = Wrestler.set_mid_card_babyfaces(id, false).to_a
@mid_card_heels = Wrestler.set_mid_card_heels(id, false).to_a
while index < num_matches
match = Match.new
@mid_card_heels.shuffle!
match.heel = @mid_card_heels.pop
@mid_card_babyfaces.shuffle!
match.babyface = @mid_card_babyfaces.pop
match.position = position
match.save
matches << match
index += 1
end
elsif position == 2
@low_card_babyfaces = Wrestler.set_low_card_babyfaces(id, false).to_a
@low_card_heels = Wrestler.set_low_card_heels(id, false).to_a
while index < num_matches
match = Match.new
@low_card_heels.shuffle!
match.heel = @low_card_heels.pop
@low_card_babyfaces.shuffle!
match.babyface = @low_card_babyfaces.pop
match.position = position
match.save
matches << match
index += 1
end
else
@undercard_babyfaces = Wrestler.set_undercard_babyfaces(id, false).to_a
@undercard_heels = Wrestler.set_undercard_heels(id, false).to_a
while index < num_matches
match = Match.new
@undercard_heels.shuffle!
match.heel = @undercard_heels.pop
@undercard_babyfaces.shuffle!
match.babyface = @undercard_babyfaces.pop
match.position = position
match.save
matches << match
index += 1
end
end
return matches
end
end