sportdb-models 1.18.5 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/Manifest.txt +27 -145
  3. data/Rakefile +4 -5
  4. data/lib/sportdb/models.rb +93 -160
  5. data/lib/sportdb/{deleter.rb → models/deleter.rb} +4 -10
  6. data/lib/sportdb/models/formats.rb +23 -0
  7. data/lib/sportdb/models/models/assoc.rb +38 -0
  8. data/lib/sportdb/models/{badge.rb → models/badge.rb} +1 -1
  9. data/lib/sportdb/models/models/event.rb +55 -0
  10. data/lib/sportdb/models/{forward.rb → models/forward.rb} +3 -3
  11. data/lib/sportdb/models/{goal.rb → models/goal.rb} +1 -1
  12. data/lib/sportdb/models/models/ground.rb +16 -0
  13. data/lib/sportdb/models/{group.rb → models/group.rb} +10 -7
  14. data/lib/sportdb/models/models/league.rb +20 -0
  15. data/lib/sportdb/models/{roster.rb → models/lineup.rb} +3 -4
  16. data/lib/sportdb/models/{game.rb → models/match.rb} +18 -61
  17. data/lib/sportdb/models/{person.rb → models/person.rb} +0 -0
  18. data/lib/sportdb/models/{round.rb → models/round.rb} +1 -6
  19. data/lib/sportdb/models/{season.rb → models/season.rb} +2 -1
  20. data/lib/sportdb/models/{stage.rb → models/stage.rb} +9 -5
  21. data/lib/sportdb/models/{stats/alltime_standing_entry.rb → models/stats/alltime_standing.rb} +9 -1
  22. data/lib/sportdb/models/{stats/event_standing_entry.rb → models/stats/event_standing.rb} +11 -1
  23. data/lib/sportdb/models/{stats/group_standing_entry.rb → models/stats/group_standing.rb} +10 -1
  24. data/lib/sportdb/models/models/team.rb +56 -0
  25. data/lib/sportdb/models/{world → models/world}/city.rb +2 -2
  26. data/lib/sportdb/models/{world → models/world}/continent.rb +0 -0
  27. data/lib/sportdb/models/{world → models/world}/country.rb +0 -0
  28. data/lib/sportdb/models/{world → models/world}/state.rb +0 -0
  29. data/lib/sportdb/{schema.rb → models/schema.rb} +165 -100
  30. data/lib/sportdb/models/stats.rb +23 -0
  31. data/lib/sportdb/models/utils.rb +24 -24
  32. data/lib/sportdb/{version.rb → models/version.rb} +12 -5
  33. data/test/helper.rb +10 -114
  34. data/test/test_changes.rb +38 -38
  35. data/test/test_cursor.rb +15 -15
  36. data/test/test_winner.rb +75 -70
  37. metadata +29 -161
  38. data/lib/sportdb/calc.rb +0 -279
  39. data/lib/sportdb/indexers/team.rb +0 -87
  40. data/lib/sportdb/mapper_teams.rb +0 -24
  41. data/lib/sportdb/matcher.rb +0 -31
  42. data/lib/sportdb/models/assoc.rb +0 -106
  43. data/lib/sportdb/models/assoc_assoc.rb +0 -15
  44. data/lib/sportdb/models/event.rb +0 -66
  45. data/lib/sportdb/models/event_ground.rb +0 -15
  46. data/lib/sportdb/models/event_team.rb +0 -16
  47. data/lib/sportdb/models/ground.rb +0 -100
  48. data/lib/sportdb/models/group_team.rb +0 -14
  49. data/lib/sportdb/models/league.rb +0 -83
  50. data/lib/sportdb/models/stage_team.rb +0 -14
  51. data/lib/sportdb/models/stats/alltime_standing.rb +0 -44
  52. data/lib/sportdb/models/stats/event_standing.rb +0 -55
  53. data/lib/sportdb/models/stats/group_standing.rb +0 -50
  54. data/lib/sportdb/models/team.rb +0 -119
  55. data/lib/sportdb/models/team_compat.rb +0 -64
  56. data/lib/sportdb/patterns.rb +0 -37
  57. data/lib/sportdb/pretty_printer.rb +0 -175
  58. data/lib/sportdb/reader.rb +0 -132
  59. data/lib/sportdb/reader_file.rb +0 -131
  60. data/lib/sportdb/reader_zip.rb +0 -172
  61. data/lib/sportdb/readers/assoc.rb +0 -54
  62. data/lib/sportdb/readers/event.rb +0 -253
  63. data/lib/sportdb/readers/event_meta.rb +0 -133
  64. data/lib/sportdb/readers/event_table.rb +0 -196
  65. data/lib/sportdb/readers/game.rb +0 -912
  66. data/lib/sportdb/readers/ground.rb +0 -53
  67. data/lib/sportdb/readers/league.rb +0 -54
  68. data/lib/sportdb/readers/season.rb +0 -83
  69. data/lib/sportdb/readers/squad_club.rb +0 -201
  70. data/lib/sportdb/readers/squad_national_team.rb +0 -173
  71. data/lib/sportdb/readers/team.rb +0 -53
  72. data/lib/sportdb/rsssf_reader.rb +0 -367
  73. data/lib/sportdb/standings.rb +0 -178
  74. data/lib/sportdb/stats.rb +0 -27
  75. data/lib/sportdb/utils.rb +0 -89
  76. data/lib/sportdb/utils_date.rb +0 -26
  77. data/lib/sportdb/utils_goals.rb +0 -20
  78. data/lib/sportdb/utils_group.rb +0 -63
  79. data/lib/sportdb/utils_map.rb +0 -44
  80. data/lib/sportdb/utils_round.rb +0 -165
  81. data/lib/sportdb/utils_scores.rb +0 -17
  82. data/lib/sportdb/utils_teams.rb +0 -48
  83. data/test/data/at-austria/2013_14/bl.txt +0 -227
  84. data/test/data/at-austria/2013_14/bl.yml +0 -30
  85. data/test/data/at-austria/2013_14/bl_ii.txt +0 -154
  86. data/test/data/at-austria/2013_14/el.txt +0 -4
  87. data/test/data/at-austria/2013_14/el.yml +0 -25
  88. data/test/data/at-austria/2013_14/squads/austria.txt +0 -40
  89. data/test/data/at-austria/2013_14/squads/salzburg.txt +0 -35
  90. data/test/data/at-austria/2014_15/1-bundesliga-ii.txt +0 -158
  91. data/test/data/at-austria/2014_15/1-bundesliga.yml +0 -18
  92. data/test/data/at-austria/2015_16/1-bundesliga-v2.conf.txt +0 -20
  93. data/test/data/at-austria/2015_16/1-bundesliga-v2.yml +0 -20
  94. data/test/data/at-austria/2015_16/1-bundesliga.conf.txt +0 -20
  95. data/test/data/at-austria/2015_16/1-bundesliga.yml +0 -24
  96. data/test/data/at-austria/2015_16/cup.yml +0 -77
  97. data/test/data/at-austria/leagues.txt +0 -11
  98. data/test/data/at-austria/teams.txt +0 -68
  99. data/test/data/at-austria/teams_2.txt +0 -21
  100. data/test/data/csv/de-2013-14--1-bundesliga.txt +0 -307
  101. data/test/data/de-deutschland/2013-14/1-bundesliga.yml +0 -26
  102. data/test/data/de-deutschland/leagues.txt +0 -4
  103. data/test/data/de-deutschland/teams.txt +0 -53
  104. data/test/data/eng-england/2015-16/1-premierleague-v2.yml +0 -2
  105. data/test/data/eng-england/2015-16/1-premierleague.yml +0 -5
  106. data/test/data/national-teams/assocs.txt +0 -231
  107. data/test/data/national-teams/europe/assocs.txt +0 -13
  108. data/test/data/national-teams/europe/teams.txt +0 -13
  109. data/test/data/national-teams/north-america/assocs.txt +0 -10
  110. data/test/data/national-teams/north-america/teams.txt +0 -7
  111. data/test/data/national-teams/teams.txt +0 -19
  112. data/test/data/players/europe/at-austria/players.txt +0 -45
  113. data/test/data/players/europe/de-deutschland/players.txt +0 -41
  114. data/test/data/players/south-america/br-brazil/players.txt +0 -51
  115. data/test/data/rsssf/at-2014-15--1-bundesliga.txt +0 -339
  116. data/test/data/rsssf/at-2015-16--1-bundesliga.txt +0 -18
  117. data/test/data/world-cup/1930/cup.txt +0 -71
  118. data/test/data/world-cup/1930/cup.yml +0 -23
  119. data/test/data/world-cup/1930/cup_goals.txt +0 -47
  120. data/test/data/world-cup/1930/cup_goals.yml +0 -23
  121. data/test/data/world-cup/1954/cup.txt +0 -90
  122. data/test/data/world-cup/1954/cup.yml +0 -30
  123. data/test/data/world-cup/1962/cup.txt +0 -86
  124. data/test/data/world-cup/1962/cup.yml +0 -32
  125. data/test/data/world-cup/1974/cup.yml +0 -35
  126. data/test/data/world-cup/1974/cup_finals.txt +0 -14
  127. data/test/data/world-cup/1974/cup_i.txt +0 -55
  128. data/test/data/world-cup/1974/cup_ii.txt +0 -34
  129. data/test/data/world-cup/2014/cup.txt +0 -5
  130. data/test/data/world-cup/2014/cup.yml +0 -54
  131. data/test/data/world-cup/2014/squads/br-brazil.txt +0 -46
  132. data/test/data/world-cup/2014/squads/de-deutschland.txt +0 -8
  133. data/test/data/world-cup/2014/squads/jp-japan.txt +0 -30
  134. data/test/data/world-cup/2014/squads/uy-uruguay.txt +0 -32
  135. data/test/data/world-cup/leagues.txt +0 -5
  136. data/test/data/world-cup/seasons_1930.txt +0 -4
  137. data/test/data/world-cup/seasons_1954.txt +0 -4
  138. data/test/data/world-cup/seasons_1962.txt +0 -4
  139. data/test/data/world-cup/seasons_1974.txt +0 -5
  140. data/test/data/world-cup/teams_1930.txt +0 -26
  141. data/test/data/world-cup/teams_1954.txt +0 -30
  142. data/test/data/world-cup/teams_1962.txt +0 -29
  143. data/test/data/world-cup/teams_1974.txt +0 -29
  144. data/test/test_assoc_reader.rb +0 -199
  145. data/test/test_event_meta_reader.rb +0 -47
  146. data/test/test_event_reader.rb +0 -64
  147. data/test/test_event_table_reader.rb +0 -57
  148. data/test/test_goals.rb +0 -107
  149. data/test/test_indexer_team.rb +0 -34
  150. data/test/test_load.rb +0 -61
  151. data/test/test_pp.rb +0 -35
  152. data/test/test_reader.rb +0 -88
  153. data/test/test_reader_from_string.rb +0 -63
  154. data/test/test_round_auto.rb +0 -370
  155. data/test/test_round_def.rb +0 -109
  156. data/test/test_round_header.rb +0 -183
  157. data/test/test_rsssf_reader.rb +0 -76
  158. data/test/test_squad_club_reader.rb +0 -76
  159. data/test/test_squad_national_team_reader.rb +0 -116
  160. data/test/test_standings.rb +0 -279
  161. data/test/test_standings_ii.rb +0 -46
  162. data/test/test_utils.rb +0 -124
@@ -1,14 +0,0 @@
1
- module SportDb
2
- module Model
3
-
4
-
5
- class GroupTeam < ActiveRecord::Base
6
- self.table_name = 'groups_teams'
7
-
8
- belongs_to :group
9
- belongs_to :team
10
- end # class GroupTeam
11
-
12
-
13
- end # module Model
14
- end # module SportDb
@@ -1,83 +0,0 @@
1
- module SportDb
2
- module Model
3
-
4
-
5
- class League < ActiveRecord::Base
6
-
7
- ## leagues also used for conferences, world series, cups, etc.
8
- #
9
- ## league (or cup/conference/series/etc.) + season (or year) = event
10
-
11
- has_many :events
12
- has_many :seasons, :through => :events
13
-
14
- belongs_to :country, :class_name => 'WorldDb::Model::Country', :foreign_key => 'country_id'
15
-
16
-
17
- def self.create_or_update_from_values( new_attributes, values )
18
-
19
- ## fix: add/configure logger for ActiveRecord!!!
20
- logger = LogKernel::Logger.root
21
-
22
- ## check optional values
23
- values.each_with_index do |value, index|
24
- if value =~ /^club$/ # club flag
25
- new_attributes[ :club ] = true
26
- elsif value =~ /^[a-z]{2}$/ ## assume two-letter country key e.g. at,de,mx,etc.
27
- value_country = Country.find_by_key!( value )
28
- new_attributes[ :country_id ] = value_country.id
29
- else
30
- ## todo: assume title2 ??
31
- ## assume title2 if title2 is empty (not already in use)
32
- ## and if it title2 contains at least two letter e.g. [a-zA-Z].*[a-zA-Z]
33
- # issue warning: unknown type for value
34
- logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}"
35
- end
36
- end
37
-
38
- logger.debug " find league key: #{new_attributes[ :key ]}"
39
-
40
- rec = League.find_by_key( new_attributes[ :key ] )
41
- if rec.present?
42
- logger.debug "update League #{rec.id}-#{rec.key}:"
43
- else
44
- logger.debug "create League:"
45
- rec = League.new
46
- end
47
-
48
- logger.debug new_attributes.to_json
49
-
50
- rec.update_attributes!( new_attributes )
51
- end # create_or_update_from_values
52
-
53
-
54
-
55
- def self.create_from_ary!( leagues, more_values={} )
56
- leagues.each do |values|
57
-
58
- ## key & title required
59
- attr = {
60
- key: values[0],
61
- title: values[1]
62
- }
63
-
64
- attr = attr.merge( more_values )
65
-
66
- ## check for optional values
67
- values[2..-1].each do |value|
68
- if value.is_a? Country
69
- attr[ :country_id ] = value.id
70
- else
71
- # issue warning: unknown type for value
72
- end
73
- end
74
-
75
- League.create!( attr )
76
- end # each league
77
- end
78
-
79
- end # class League
80
-
81
-
82
- end # module Model
83
- end # module SportDb
@@ -1,14 +0,0 @@
1
- module SportDb
2
- module Model
3
-
4
-
5
- class StageTeam < ActiveRecord::Base
6
- self.table_name = 'stages_teams'
7
-
8
- belongs_to :stage
9
- belongs_to :team
10
- end # class StageTeam
11
-
12
-
13
- end # module Model
14
- end # module SportDb
@@ -1,44 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
- module Model
5
-
6
-
7
- class AlltimeStanding < ActiveRecord::Base
8
-
9
- self.table_name = 'alltime_standings'
10
-
11
- has_many :entries, class_name: 'SportDb::Model::AlltimeStandingEntry', foreign_key: 'alltime_standing_id', :dependent => :delete_all
12
-
13
-
14
- def recalc_for_league!( league, opts={} )
15
-
16
- recs = StandingsHelper.calc_for_events( league.events, opts )
17
-
18
- ## - remove (if exit) old entries and add new entries
19
- entries.delete_all # note: assoc dependent set to :delete_all (defaults to :nullify)
20
-
21
- recs.each do |team_key,rec|
22
-
23
- team = Team.find_by_key!( team_key )
24
- ### note: we also add rec.recs (appearance counter) - not included w/ group or event standings, for example
25
- entries.create!(
26
- team_id: team.id,
27
- pos: rec.pos,
28
- played: rec.played,
29
- won: rec.won,
30
- drawn: rec.drawn,
31
- lost: rec.lost,
32
- goals_for: rec.goals_for,
33
- goals_against: rec.goals_against,
34
- pts: rec.pts,
35
- recs: rec.recs )
36
- end
37
- end # method recalc_for_league!
38
-
39
-
40
- end # class AlltimeStanding
41
-
42
-
43
- end # module Model
44
- end # module SportDb
@@ -1,55 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
- module Model
5
-
6
-
7
- class EventStanding < ActiveRecord::Base
8
-
9
- self.table_name = 'event_standings'
10
-
11
- has_many :entries, class_name: 'SportDb::Model::EventStandingEntry', foreign_key: 'event_standing_id', :dependent => :delete_all
12
- belongs_to :event
13
-
14
- ## convenience helper; recalcs all records
15
- def self.recalc!( opts={} ) self.order(:id).each { |rec| rec.recalc!(opts) }; end
16
-
17
-
18
- def recalc!( opts={} )
19
- ## will calculate event standing e.g.
20
-
21
- ## calc points (pts) - loop over all group games/matches
22
- # group.games.each do |game|
23
- # end
24
-
25
- # todo/fix!!!!!!!!!!:
26
- # skip knockout rounds - why? why not?
27
- # make it configure-able?
28
-
29
- recs = StandingsHelper.calc( event.games, opts )
30
-
31
- ## - remove (if exit) old entries and add new entries
32
- entries.delete_all # note: assoc dependent set to :delete_all (defaults to :nullify)
33
-
34
- ## add empty entries
35
- event.teams.each do |team|
36
- puts " adding entry for team #{team.title} (#{team.code})"
37
- rec = recs[ team.key ] # find (in-memory) stats records
38
- entries.create!(
39
- team_id: team.id,
40
- pos: rec.pos,
41
- played: rec.played,
42
- won: rec.won,
43
- drawn: rec.drawn,
44
- lost: rec.lost,
45
- goals_for: rec.goals_for,
46
- goals_against: rec.goals_against,
47
- pts: rec.pts )
48
- end
49
- end # method recalc!
50
-
51
-
52
- end # class EventStanding
53
- end # module Model
54
-
55
- end # module SportDb
@@ -1,50 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
- module Model
5
-
6
-
7
- class GroupStanding < ActiveRecord::Base
8
-
9
- self.table_name = 'group_standings'
10
-
11
- has_many :entries, class_name: 'SportDb::Model::GroupStandingEntry', foreign_key: 'group_standing_id', :dependent => :delete_all
12
- belongs_to :group
13
-
14
- ## convenience helper; recalcs all records
15
- def self.recalc!( opts={} ) self.order(:id).each { |rec| rec.recalc!(opts) }; end
16
-
17
-
18
- def recalc!( opts={} )
19
- ## will calculate group standing e.g.
20
-
21
- ## calc points (pts) - loop over all group games/matches
22
- # group.games.each do |game|
23
- # end
24
- recs = StandingsHelper.calc( group.games, opts )
25
-
26
- ## - remove (if exit) old entries and add new entries
27
- entries.delete_all # note: assoc dependent set to :delete_all (defaults to :nullify)
28
-
29
- ## add empty entries
30
- group.teams.each do |team|
31
- puts " adding entry for team #{team.title} (#{team.code})"
32
- rec = recs[ team.key ] # find (in-memory) stats records
33
- entries.create!(
34
- team_id: team.id,
35
- pos: rec.pos,
36
- played: rec.played,
37
- won: rec.won,
38
- drawn: rec.drawn,
39
- lost: rec.lost,
40
- goals_for: rec.goals_for,
41
- goals_against: rec.goals_against,
42
- pts: rec.pts )
43
- end
44
- end # method recalc!
45
-
46
-
47
- end # class GroupStanding
48
- end # module Model
49
-
50
- end # module SportDb
@@ -1,119 +0,0 @@
1
-
2
- module SportDb
3
- module Model
4
-
5
- ##################
6
- # FIX: add ?
7
- #
8
- # use single table inheritance STI ????
9
- # - to mark two dervided classes e.g.
10
- # - Club ??? - why? why not?
11
- # - NationalTeam ??? - why? why not?
12
-
13
-
14
- class Team < ActiveRecord::Base
15
-
16
- has_many :home_games, class_name: 'Game', foreign_key: 'team1_id'
17
- has_many :away_games, class_name: 'Game', foreign_key: 'team2_id'
18
-
19
- ## todo/fix: must be 3 or more letters (plus allow digits e.g. salzburgii, muenchen1980, etc.) - why? why not??
20
- validates :key, format: { with: /#{TEAM_KEY_PATTERN}/, message: TEAM_KEY_PATTERN_MESSAGE }
21
- validates :code, format: { with: /#{TEAM_CODE_PATTERN}/, message: TEAM_CODE_PATTERN_MESSAGE }, allow_nil: true
22
-
23
- has_many :event_teams, class_name: 'EventTeam' # join table (events+teams)
24
- has_many :events, :through => :event_teams
25
-
26
- # note: team belongs_to a single (optinal) assoc for now (national assoc may have many assocs)
27
- belongs_to :assoc
28
-
29
- ### fix!!! - how to do it with has_many macro? use finder_sql?
30
- ## finder_sql is depreciated in Rails 4!!!
31
- # use -> { where() } etc. -- try it if it works
32
- ## keep as is! best solution ??
33
- ## a discussion here -> https://github.com/rails/rails/issues/9726
34
- ## a discussion here (not really helpful) -> http://stackoverflow.com/questions/2125440/activerecord-has-many-where-two-columns-in-table-a-are-primary-keys-in-table-b
35
-
36
- def games
37
- Game.where( 'team1_id = ? or team2_id = ?', id, id ).order( 'play_at' )
38
- end
39
-
40
- def upcoming_games
41
- Game.where( 'team1_id = ? or team2_id = ?', id, id ).where( 'play_at > ?', Time.now ).order( 'play_at' )
42
- end
43
-
44
- def past_games
45
- Game.where( 'team1_id = ? or team2_id = ?', id, id ).where( 'play_at < ?', Time.now ).order( 'play_at desc' )
46
- end
47
-
48
-
49
- has_many :badges # Winner, 2nd, Cupsieger, Aufsteiger, Absteiger, etc.
50
-
51
- belongs_to :country, class_name: 'WorldDb::Model::Country', foreign_key: 'country_id'
52
- belongs_to :city, class_name: 'WorldDb::Model::City', foreign_key: 'city_id'
53
-
54
-
55
- ## fix/todo: change title to name; title2 to name2 etc.
56
- def name() title; end
57
-
58
-
59
- def self.create_or_update_from_values( new_attributes, values )
60
-
61
- ## fix: add/configure logger for ActiveRecord!!!
62
- logger = LogUtils::Logger.root
63
-
64
-
65
- ## check optional values
66
- values.each_with_index do |value, index|
67
- if value =~ /^city:/ ## city:
68
- value_city_key = value[5..-1] ## cut off city: prefix
69
- value_city = City.find_by_key( value_city_key )
70
- if value_city.present?
71
- new_attributes[ :city_id ] = value_city.id
72
- else
73
- ## todo/fix: add strict mode flag - fail w/ exit 1 in strict mode
74
- logger.warn "city with key #{value_city_key} missing"
75
- ## todo: log errors to db log???
76
- end
77
- elsif value =~ /^(18|19|20)[0-9]{2}$/ ## assume founding year -- allow 18|19|20
78
- ## logger.info " founding/opening year #{value}"
79
- new_attributes[ :since ] = value.to_i
80
- elsif value =~ /\/{2}/ # assume it's an address line e.g. xx // xx
81
- ## logger.info " found address line #{value}"
82
- new_attributes[ :address ] = value
83
- elsif value =~ /^(?:[a-z]{2}\.)?wikipedia:/ # assume it's wikipedia e.g. [es.]wikipedia:
84
- logger.info " found wikipedia line #{value}; skipping for now"
85
- elsif value =~ /(^www\.)|(\.com$)/ # FIX: !!!! use a better matcher not just www. and .com
86
- new_attributes[ :web ] = value
87
- elsif value =~ /^[A-Z][A-Z0-9][A-Z0-9_]?$/ ## assume two or three-letter code e.g. FCB, RBS, etc.
88
- new_attributes[ :code ] = value
89
- elsif value =~ /^[a-z]{2,3}$/ ## assume two or three-letter country key e.g. at,de,mx, or eng,sco,wal,nir etc.
90
- ## fix: if country does NOT match / NOT found - just continue w/ next match!!!!
91
- # - just issue an error/warn do NOT crash
92
- value_country = Country.find_by_key!( value )
93
- new_attributes[ :country_id ] = value_country.id
94
- else
95
- ## todo: assume title2 ??
96
- # issue warning: unknown type for value
97
- logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}"
98
- end
99
- end
100
-
101
- rec = Team.find_by_key( new_attributes[ :key ] )
102
- if rec.present?
103
- logger.debug "update Team #{rec.id}-#{rec.key}:"
104
- else
105
- logger.debug "create Team:"
106
- rec = Team.new
107
- end
108
-
109
- logger.debug new_attributes.to_json
110
-
111
- rec.update_attributes!( new_attributes )
112
-
113
- end # create_or_update_from_values
114
-
115
- end # class Team
116
-
117
-
118
- end # module Model
119
- end # module SportDb
@@ -1,64 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
- module Model
5
-
6
- #############################################################
7
- # collect depreciated or methods for future removal here
8
- # - keep for now for compatibility (for old code)
9
-
10
- class Team
11
-
12
-
13
- def self.create_from_ary!( teams, more_values={} )
14
- teams.each do |values|
15
-
16
- ## key & title required
17
- attr = {
18
- key: values[0]
19
- }
20
-
21
- ## title (split of optional synonyms)
22
- # e.g. FC Bayern Muenchen|Bayern Muenchen|Bayern
23
- titles = values[1].split('|')
24
-
25
- attr[ :title ] = titles[0]
26
- ## add optional synonyms
27
- attr[ :synonyms ] = titles[1..-1].join('|') if titles.size > 1
28
-
29
-
30
- attr = attr.merge( more_values )
31
-
32
- ## check for optional values
33
- values[2..-1].each do |value|
34
- if value.is_a? Country
35
- attr[ :country_id ] = value.id
36
- elsif value.is_a? City
37
- attr[ :city_id ] = value.id
38
- elsif value =~ /#{TEAM_CODE_PATTERN}/ ## assume its three letter code (e.g. ITA or S04 etc.)
39
- attr[ :code ] = value
40
- elsif value =~ /^city:/ ## city:
41
- value_city_key = value[5..-1] ## cut off city: prefix
42
- value_city = City.find_by_key!( value_city_key )
43
- attr[ :city_id ] = value_city.id
44
- else
45
- attr[ :title2 ] = value
46
- end
47
- end
48
-
49
- ## check if exists
50
- team = Team.find_by_key( values[0] )
51
- if team.present?
52
- puts "*** warning team with key '#{values[0]}' exists; skipping create"
53
- else
54
- Team.create!( attr )
55
- end
56
- end # each team
57
- end
58
-
59
- end # class Team
60
-
61
-
62
-
63
- end # module Model
64
- end # module SportDb