Sha256: 939d32e2ce9869d88ef8302fc8fb655f2f672d89d024d8898e585a8dde6d4caa
Contents?: true
Size: 1.46 KB
Versions: 42
Compression:
Stored size: 1.46 KB
Contents
# encoding: utf-8 module SportDb module Model class GroupStanding < ActiveRecord::Base self.table_name = 'group_standings' has_many :entries, class_name: 'SportDb::Model::GroupStandingEntry', foreign_key: 'group_standing_id', :dependent => :delete_all belongs_to :group ## convenience helper; recalcs all records def self.recalc!( opts={} ) self.order(:id).each { |rec| rec.recalc!(opts) }; end def recalc!( opts={} ) ## will calculate group standing e.g. ## calc points (pts) - loop over all group games/matches # group.games.each do |game| # end recs = StandingsHelper.calc( group.games, opts ) ## - remove (if exit) old entries and add new entries entries.delete_all # note: assoc dependent set to :delete_all (defaults to :nullify) ## add empty entries group.teams.each do |team| puts " adding entry for team #{team.title} (#{team.code})" rec = recs[ team.key ] # find (in-memory) stats records entries.create!( team_id: team.id, pos: rec.pos, played: rec.played, won: rec.won, drawn: rec.drawn, lost: rec.lost, goals_for: rec.goals_for, goals_against: rec.goals_against, pts: rec.pts ) end end # method recalc! end # class GroupStanding end # module Model end # module SportDb
Version data entries
42 entries across 42 versions & 2 rubygems
Version | Path |
---|---|
sportdb-1.9.2 | lib/sportdb/models/stats/group_standing.rb |
sportdb-1.9.1 | lib/sportdb/models/stats/group_standing.rb |