Sha256: 5bb89a17ad3a1f0a9f4b96f7a834cc391a4a30881feba5ef22201313da3f98cd

Contents?: true

Size: 1.21 KB

Versions: 8

Compression:

Stored size: 1.21 KB

Contents

# encoding: utf-8

module SportDb::Models

class Event < ActiveRecord::Base

  belongs_to :league
  belongs_to :season
  
  has_many :rounds, :order => 'pos'  # all (fix and flex) rounds
  has_many :games, :through => :rounds
  
  has_many :groups, :order => 'pos'
  
  has_many :event_teams, :class_name => 'EventTeam'
  has_many :teams, :through => :event_teams

  before_save :on_before_save

  def add_teams_from_ary!( team_keys )
    team_keys.each do |team_key|
      team = Team.find_by_key!( team_key )
      self.teams << team
    end
  end

  def on_before_save
    # event key is composite of league + season (e.g. at.2012/13) etc.
    self.key = "#{league.key}.#{season.key}"
  end
  
  def title
    league.title
  end

  def full_title   # includes season (e.g. year)
    "#{league.title} #{season.title}"
  end


  #####################
  ## convenience helper for text parser/reader

  ###
  ## fix: use/add  to_teams_table( rec )  for reuse
  #
  ##  @known_teams = @event.known_teams_table


  def known_teams_table
    @known_teams_table ||= TextUtils.build_title_table_for( teams )
  end # method known_teams_table

end # class Event

end # module SportDb::Models

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
sportdb-1.7.1 lib/sportdb/models/event.rb
sportdb-1.7.0 lib/sportdb/models/event.rb
sportdb-1.6.18 lib/sportdb/models/event.rb
sportdb-1.6.17 lib/sportdb/models/event.rb
sportdb-1.6.16 lib/sportdb/models/event.rb
sportdb-1.6.15 lib/sportdb/models/event.rb
sportdb-1.6.14 lib/sportdb/models/event.rb
sportdb-1.6.13 lib/sportdb/models/event.rb