/
event.rb
57 lines (39 loc) · 1.34 KB
/
event.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# encoding: utf-8
module SportDb::Model
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} #{season.title}"
end
def full_title # includes season (e.g. year)
puts "*** depreciated API call Event#full_title; use Event#title instead; full_title will get removed"
"#{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::Model