lib/sportdb/models/game.rb in sportdb-0.7.1 vs lib/sportdb/models/game.rb in sportdb-0.7.2

- old
+ new

@@ -139,10 +139,12 @@ game2.prev_game_id = game1.id game2.save! end # each pair end + + def calc_toto12x if score1.nil? || score2.nil? self.toto12x = nil elsif score1 == score2 @@ -151,9 +153,44 @@ 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 + def knockout? + knockout == true + end + + def complete? + score1.present? && score2.present? + end + +############# convenience helpers for styling +## + + 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 + 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 + end + + end # class Game end # module SportDB::Models