lib/sportdb/models/game.rb in sportdb-1.7.0 vs lib/sportdb/models/game.rb in sportdb-1.7.1
- old
+ new
@@ -14,33 +14,49 @@
before_save :calc_toto12x
### getter/setters for deprecated attribs (score3,4,5,6) n national
def score3
- score1ot
+ score1et
end
def score4
- score2ot
+ score2et
end
+
+ def score1ot
+ score1et
+ end
+ def score2ot
+ score2et
+ end
+
def score5
score1p
end
def score6
score2p
end
def score3=(value)
- self.score1ot = value
+ self.score1et = value
end
def score4=(value)
- self.score2ot = value
+ self.score2et = value
end
+ def score1ot=(value)
+ self.score1et = value
+ end
+
+ def score2ot=(value)
+ self.score2et = value
+ end
+
def score5=(value)
self.score1p = value
end
def score6=(value)
@@ -93,12 +109,12 @@
:round => round,
:pos => value_pos,
:team1 => value_teams[0],
:score1 => value_scores[0],
:score2 => value_scores[1],
- :score1ot => value_scores[2],
- :score2ot => value_scores[3],
+ :score1et => value_scores[2],
+ :score2et => value_scores[3],
:score1p => value_scores[4],
:score2p => value_scores[5],
:team2 => value_teams[1],
:play_at => value_play_at,
:group => value_group, # Note: group is optional (may be null/nil)
@@ -157,12 +173,12 @@
:round =>round2,
:pos =>pair[1][0],
:team1 =>pair[1][1],
:score1 =>pair[1][2][0],
:score2 =>pair[1][2][1],
- :score1ot =>pair[1][2][2],
- :score2ot =>pair[1][2][3],
+ :score1et =>pair[1][2][2],
+ :score2et =>pair[1][2][3],
:score1p =>pair[1][2][4],
:score1p =>pair[1][2][5],
:team2 =>pair[1][3],
:play_at =>pair[1][4],
:knockout =>true }
@@ -190,12 +206,12 @@
self.toto12x = '1'
elsif score1 < score2
self.toto12x = '2'
end
end
-
+
def over? # game over?
play_at <= Time.now
end
## fix/todo: already added by ar magic ??? remove code
@@ -213,20 +229,58 @@
def team1_style_class
buf = ''
## NB: remove if calc?
buf << 'game-team-winner ' if complete? && (score1 > score2)
buf << 'game-team-draw ' if complete? && (score1 == score2)
+ buf << 'game-knockout ' if knockout?
+ ### fix: loser - add method for checking winner/loser on ko pairs using (1st leg/2nd leg totals)
+ buf << 'game-team-loser ' if complete? && (score1 < score2)
buf
end
def team2_style_class
buf = ''
## NB: remove if calc?
buf << 'game-team-winner ' if complete? && (score2 > score1)
buf << 'game-team-draw ' if complete? && (score2 == score1)
+ buf << 'game-knockout ' if knockout?
+ ### fix: loser - add method for checking winner/loser on ko pairs using (1st leg/2nd leg totals)
+ buf << 'game-team-loser ' if complete? && (score2 < score1)
buf
end
+
+ def play_at_str( format = nil )
+ ## e.g. use like
+ # play_at_str or
+ # play_at_str( :db ) etc.
+ if format == :db
+ play_at.strftime( '%Y-%m-%d %H:%M %z' ) # NB: removed seconds (:%S)
+ else
+ play_at.strftime( "%a. %d. %b. / %H:%M" )
+ end
+ end
+
+
+ def score_str
+ return ' - ' if score1.blank? && score2.blank?
+
+ if score1p.present? && score2p.present? # im Elfmeterschiessen i.E.?
+ "#{score1_str} : #{score2_str} / #{score1et} : #{score2et} n.V. / #{score1p} : #{score2p} i.E."
+ elsif score1et.present? && score2et.present? # nach Verlaengerung n.V.?
+ "#{score1_str} : #{score2_str} / #{score1et} : #{score2et} n.V."
+ else
+ "#{score1_str} : #{score2_str}"
+ end
+ end
+
+ def score1_str
+ if score1.blank? then '-' else score1.to_s end
+ end
+
+ def score2_str
+ if score2.blank? then '-' else score2.to_s end
+ end
end # class Game