Class: SportDB::Game

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/sportdb/models.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_from_ary!(games, round, knockout = false) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/sportdb/models.rb', line 58

def self.create_from_ary!( games, round, knockout=false )
  games.each do |values|
    Game.create!(
      :round     =>round,
      :pos       =>values[0],
      :team1     =>values[1],
      :score1    =>values[2][0],
      :score2    =>values[2][1],
      :score3    =>values[2][2],
      :score4    =>values[2][3],
      :score5    =>values[2][4],
      :score6    =>values[2][5],
      :team2     =>values[3],
      :play_at   =>values[4],
      :group     =>values[5],    # Note: group is optional (may be null/nil)
      :knockout  =>knockout )
  end # each games
end

.create_knockout_pairs_from_ary!(pairs, round1, round2) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/sportdb/models.rb', line 112

def self.create_knockout_pairs_from_ary!( pairs, round1, round2 )
  
  pairs.each do |pair|
    game1_attribs = {
      :round     =>round1,
      :pos       =>pair[0][0],
      :team1     =>pair[0][1],
      :score1    =>pair[0][2][0],
      :score2    =>pair[0][2][1],
      :team2     =>pair[0][3],
      :play_at   =>pair[0][4] }

    game2_attribs = {
      :round     =>round2,
      :pos       =>pair[1][0],
      :team1     =>pair[1][1],
      :score1    =>pair[1][2][0],
      :score2    =>pair[1][2][1],
      :score3    =>pair[1][2][2],
      :score4    =>pair[1][2][3],
      :score5    =>pair[1][2][4],
      :score6    =>pair[1][2][5],
      :team2     =>pair[1][3],
      :play_at   =>pair[1][4],
      :knockout  =>true }

    game1 = Game.create!( game1_attribs )
    game2 = Game.create!( game2_attribs )

    # linkup games
    game1.next_game_id = game2.id
    game1.save!

    game2.prev_game_id = game1.id
    game2.save!
  end # each pair
end

.create_knockouts_from_ary!(games, round) ⇒ Object



54
55
56
# File 'lib/sportdb/models.rb', line 54

def self.create_knockouts_from_ary!( games, round )
  Game.create_from_ary!( games, round, true )
end

.create_pairs_from_ary_for_group!(pairs, group) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/sportdb/models.rb', line 77

def self.create_pairs_from_ary_for_group!( pairs, group )
  
  pairs.each do |pair|
    game1_attribs = {
      :round     =>pair[0][5],
      :pos       =>pair[0][0],
      :team1     =>pair[0][1],
      :score1    =>pair[0][2][0],
      :score2    =>pair[0][2][1],
      :team2     =>pair[0][3],
      :play_at   =>pair[0][4],
      :group     =>group }

    game2_attribs = {
      :round     =>pair[1][5],
      :pos       =>pair[1][0],
      :team1     =>pair[1][1],
      :score1    =>pair[1][2][0],
      :score2    =>pair[1][2][1],
      :team2     =>pair[1][3],
      :play_at   =>pair[1][4],
      :group     =>group }

    game1 = Game.create!( game1_attribs )
    game2 = Game.create!( game2_attribs )

    # linkup games
    game1.next_game_id = game2.id
    game1.save!

    game2.prev_game_id = game1.id
    game2.save!
  end # each pair
end

Instance Method Details

#calc_toto12xObject



150
151
152
153
154
155
156
157
158
159
160
# File 'lib/sportdb/models.rb', line 150

def calc_toto12x
  if score1.nil? || score2.nil?
    self.toto12x = nil
  elsif score1 == score2
    self.toto12x = 'X'
  elsif score1 > score2
    self.toto12x = '1'
  elsif score1 < score2
    self.toto12x = '2'
  end
end