sportdb 1.9.16 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. checksums.yaml +4 -4
  2. data/HISTORY.md +2 -19
  3. data/Manifest.txt +1 -137
  4. data/README.md +2 -21
  5. data/Rakefile +14 -25
  6. data/lib/sportdb.rb +9 -260
  7. data/lib/sportdb/cli/main.rb +5 -14
  8. data/lib/sportdb/cli/opts.rb +2 -0
  9. data/lib/sportdb/cli/version.rb +26 -0
  10. metadata +10 -278
  11. data/.gemtest +0 -0
  12. data/config/fixtures/de.yml +0 -46
  13. data/config/fixtures/en.yml +0 -54
  14. data/config/fixtures/es.yml +0 -48
  15. data/config/fixtures/fr.yml +0 -53
  16. data/config/fixtures/it.yml +0 -55
  17. data/config/fixtures/pt.yml +0 -46
  18. data/config/fixtures/ro.yml +0 -55
  19. data/data/seasons.txt +0 -74
  20. data/data/setups/all.txt +0 -5
  21. data/lib/sportdb/calc.rb +0 -279
  22. data/lib/sportdb/deleter.rb +0 -52
  23. data/lib/sportdb/finders/date.rb +0 -374
  24. data/lib/sportdb/finders/goals.rb +0 -260
  25. data/lib/sportdb/finders/scores.rb +0 -122
  26. data/lib/sportdb/lang.rb +0 -216
  27. data/lib/sportdb/matcher.rb +0 -31
  28. data/lib/sportdb/models/assoc.rb +0 -106
  29. data/lib/sportdb/models/assoc_assoc.rb +0 -15
  30. data/lib/sportdb/models/badge.rb +0 -14
  31. data/lib/sportdb/models/event.rb +0 -65
  32. data/lib/sportdb/models/event_ground.rb +0 -15
  33. data/lib/sportdb/models/event_team.rb +0 -16
  34. data/lib/sportdb/models/forward.rb +0 -55
  35. data/lib/sportdb/models/game.rb +0 -244
  36. data/lib/sportdb/models/goal.rb +0 -15
  37. data/lib/sportdb/models/ground.rb +0 -100
  38. data/lib/sportdb/models/group.rb +0 -23
  39. data/lib/sportdb/models/group_team.rb +0 -14
  40. data/lib/sportdb/models/league.rb +0 -83
  41. data/lib/sportdb/models/person.rb +0 -21
  42. data/lib/sportdb/models/roster.rb +0 -18
  43. data/lib/sportdb/models/round.rb +0 -22
  44. data/lib/sportdb/models/season.rb +0 -14
  45. data/lib/sportdb/models/stats/alltime_standing.rb +0 -44
  46. data/lib/sportdb/models/stats/alltime_standing_entry.rb +0 -23
  47. data/lib/sportdb/models/stats/event_standing.rb +0 -55
  48. data/lib/sportdb/models/stats/event_standing_entry.rb +0 -21
  49. data/lib/sportdb/models/stats/group_standing.rb +0 -50
  50. data/lib/sportdb/models/stats/group_standing_entry.rb +0 -22
  51. data/lib/sportdb/models/team.rb +0 -119
  52. data/lib/sportdb/models/team_comp.rb +0 -64
  53. data/lib/sportdb/models/utils.rb +0 -78
  54. data/lib/sportdb/models/world/city.rb +0 -21
  55. data/lib/sportdb/models/world/continent.rb +0 -20
  56. data/lib/sportdb/models/world/country.rb +0 -19
  57. data/lib/sportdb/models/world/region.rb +0 -19
  58. data/lib/sportdb/patterns.rb +0 -38
  59. data/lib/sportdb/reader.rb +0 -130
  60. data/lib/sportdb/reader_file.rb +0 -123
  61. data/lib/sportdb/reader_zip.rb +0 -165
  62. data/lib/sportdb/readers/assoc.rb +0 -54
  63. data/lib/sportdb/readers/event.rb +0 -200
  64. data/lib/sportdb/readers/game.rb +0 -877
  65. data/lib/sportdb/readers/ground.rb +0 -53
  66. data/lib/sportdb/readers/league.rb +0 -54
  67. data/lib/sportdb/readers/season.rb +0 -83
  68. data/lib/sportdb/readers/squad_club.rb +0 -201
  69. data/lib/sportdb/readers/squad_national_team.rb +0 -173
  70. data/lib/sportdb/readers/team.rb +0 -53
  71. data/lib/sportdb/schema.rb +0 -373
  72. data/lib/sportdb/standings.rb +0 -178
  73. data/lib/sportdb/stats.rb +0 -27
  74. data/lib/sportdb/utils.rb +0 -89
  75. data/lib/sportdb/utils_date.rb +0 -26
  76. data/lib/sportdb/utils_goals.rb +0 -20
  77. data/lib/sportdb/utils_group.rb +0 -63
  78. data/lib/sportdb/utils_map.rb +0 -44
  79. data/lib/sportdb/utils_round.rb +0 -165
  80. data/lib/sportdb/utils_scores.rb +0 -17
  81. data/lib/sportdb/utils_teams.rb +0 -43
  82. data/lib/sportdb/version.rb +0 -22
  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/leagues.txt +0 -11
  91. data/test/data/at-austria/teams.txt +0 -75
  92. data/test/data/at-austria/teams_2.txt +0 -34
  93. data/test/data/national-teams/assocs.txt +0 -231
  94. data/test/data/national-teams/europe/assocs.txt +0 -13
  95. data/test/data/national-teams/europe/teams.txt +0 -13
  96. data/test/data/national-teams/north-america/assocs.txt +0 -10
  97. data/test/data/national-teams/north-america/teams.txt +0 -7
  98. data/test/data/national-teams/teams.txt +0 -19
  99. data/test/data/players/europe/at-austria/players.txt +0 -45
  100. data/test/data/players/europe/de-deutschland/players.txt +0 -41
  101. data/test/data/players/south-america/br-brazil/players.txt +0 -51
  102. data/test/data/world-cup/1930/cup.txt +0 -71
  103. data/test/data/world-cup/1930/cup.yml +0 -23
  104. data/test/data/world-cup/1930/cup_goals.txt +0 -47
  105. data/test/data/world-cup/1930/cup_goals.yml +0 -23
  106. data/test/data/world-cup/1954/cup.txt +0 -90
  107. data/test/data/world-cup/1954/cup.yml +0 -30
  108. data/test/data/world-cup/1962/cup.txt +0 -86
  109. data/test/data/world-cup/1962/cup.yml +0 -32
  110. data/test/data/world-cup/1974/cup.yml +0 -35
  111. data/test/data/world-cup/1974/cup_finals.txt +0 -14
  112. data/test/data/world-cup/1974/cup_i.txt +0 -55
  113. data/test/data/world-cup/1974/cup_ii.txt +0 -34
  114. data/test/data/world-cup/2014/cup.txt +0 -5
  115. data/test/data/world-cup/2014/cup.yml +0 -54
  116. data/test/data/world-cup/2014/squads/br-brazil.txt +0 -46
  117. data/test/data/world-cup/2014/squads/de-deutschland.txt +0 -8
  118. data/test/data/world-cup/2014/squads/jp-japan.txt +0 -30
  119. data/test/data/world-cup/2014/squads/uy-uruguay.txt +0 -32
  120. data/test/data/world-cup/leagues.txt +0 -5
  121. data/test/data/world-cup/seasons_1930.txt +0 -4
  122. data/test/data/world-cup/seasons_1954.txt +0 -4
  123. data/test/data/world-cup/seasons_1962.txt +0 -4
  124. data/test/data/world-cup/seasons_1974.txt +0 -5
  125. data/test/data/world-cup/teams_1930.txt +0 -26
  126. data/test/data/world-cup/teams_1954.txt +0 -30
  127. data/test/data/world-cup/teams_1962.txt +0 -29
  128. data/test/data/world-cup/teams_1974.txt +0 -29
  129. data/test/helper.rb +0 -120
  130. data/test/test_assoc_reader.rb +0 -201
  131. data/test/test_changes.rb +0 -74
  132. data/test/test_cursor.rb +0 -50
  133. data/test/test_date.rb +0 -100
  134. data/test/test_goals.rb +0 -109
  135. data/test/test_lang.rb +0 -130
  136. data/test/test_load.rb +0 -61
  137. data/test/test_reader.rb +0 -88
  138. data/test/test_reader_from_string.rb +0 -65
  139. data/test/test_round_auto.rb +0 -370
  140. data/test/test_round_def.rb +0 -109
  141. data/test/test_round_header.rb +0 -183
  142. data/test/test_scores.rb +0 -70
  143. data/test/test_squad_club_reader.rb +0 -76
  144. data/test/test_squad_national_team_reader.rb +0 -116
  145. data/test/test_standings.rb +0 -279
  146. data/test/test_standings_ii.rb +0 -46
  147. data/test/test_utils.rb +0 -124
  148. data/test/test_winner.rb +0 -95
@@ -1,122 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
-
5
- class ScoresFinder
6
-
7
- include LogUtils::Logging
8
-
9
- # e.g. 1:2 or 0:2 or 3:3 or
10
- # 1-1 or 0-2 or 3-3
11
- FT_REGEX = /\b
12
- (?<score1>\d{1,2})
13
- [:\-]
14
- (?<score2>\d{1,2})
15
- \b/x
16
-
17
-
18
- # e.g. 1:2nV => after extra time a.e.t
19
-
20
- # note: possible ending w/ . -> thus cannot use /b will not work w/ .; use zero look-ahead
21
- ET_REGEX = /\b
22
- (?<score1>\d{1,2})
23
- [:\-]
24
- (?<score2>\d{1,2})
25
- \s? # allow optional space
26
- (?:nV|n\.V\.|aet|a\.e\.t\.) # allow optional . e.g. nV or n.V.
27
- (?=[\s\)\]]|$)/xi
28
-
29
- ## todo: add/allow english markers e.g. pen or p ??
30
-
31
- # e.g. 5:4iE => penalty / after penalty a.p
32
-
33
-
34
- # note: possible ending w/ . -> thus cannot use /b will not work w/ .; use zero look-ahead
35
- P_REGEX = /\b
36
- (?<score1>\d{1,2})
37
- [:\-]
38
- (?<score2>\d{1,2})
39
- \s? # allow optional space
40
- (?:iE|i\.E\.|p|pen|PSO) # allow optional . e.g. iE or i.E.
41
- (?=[\s\)\]]|$)/xi
42
-
43
-
44
- ## todo: allow all-in-one "literal form a la kicker" e.g.
45
- # 2:2 (1:1, 1:0) n.V. 5:1 i.E.
46
-
47
- def initialize
48
- # nothing here for now
49
- end
50
-
51
- def find!( line, opts={} )
52
-
53
- ### fix: add and match all-in-one literal first, followed by
54
-
55
- # note: always call after find_dates !!!
56
- # scores match date-like patterns!! e.g. 10-11 or 10:00 etc.
57
- # -- note: score might have two digits too
58
-
59
- ### fix: depending on language allow 1:1 or 1-1
60
- ## do NOT allow mix and match
61
- ## e.g. default to en is 1-1
62
- ## de is 1:1 etc.
63
-
64
-
65
- # extract score from line
66
- # and return it
67
- # NB: side effect - removes date from line string
68
-
69
- score1 = nil
70
- score2 = nil
71
-
72
- score1et = nil
73
- score2et = nil
74
-
75
- score1p = nil
76
- score2p = nil
77
-
78
- if (md = ET_REGEX.match( line ))
79
- score1et = md[:score1].to_i
80
- score2et = md[:score2].to_i
81
-
82
- logger.debug " score.et: >#{score1et}-#{score2et}<"
83
-
84
- line.sub!( md[0], '[SCORE.ET]' )
85
- end
86
-
87
- if (md = P_REGEX.match( line ))
88
- score1p = md[:score1].to_i
89
- score2p = md[:score2].to_i
90
-
91
- logger.debug " score.p: >#{score1p}-#{score2p}<"
92
-
93
- line.sub!( md[0], '[SCORE.P]' )
94
- end
95
-
96
- ## let full time (ft) standard regex go last - has no marker
97
-
98
- if (md = FT_REGEX.match( line ))
99
- score1 = md[:score1].to_i
100
- score2 = md[:score2].to_i
101
-
102
- logger.debug " score: >#{score1}-#{score2}<"
103
-
104
- line.sub!( md[0], '[SCORE]' )
105
- end
106
-
107
- ## todo: how to handle game w/o extra time
108
- # but w/ optional penalty ??? e.g. used in copa liberatores, for example
109
- # retrun 0,0 or nil,nil for extra time score ?? or -1, -1 ??
110
- # for now use nil,nil
111
-
112
- scores = []
113
- scores += [score1, score2] if score1p || score2p || score1et || score2et || score1 || score2
114
- scores += [score1et, score2et] if score1p || score2p || score1et || score2et
115
- scores += [score1p, score2p] if score1p || score2p
116
-
117
- scores
118
- end
119
-
120
- end # class ScoresFinder
121
-
122
- end # module SportDb
@@ -1,216 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
-
5
- class Lang
6
-
7
- include LogUtils::Logging
8
-
9
- attr_reader :lang
10
-
11
- def initialize
12
- # fix/todo: load on demand; only if no fixtures loaded/configured use builtin
13
- load_builtin_words
14
- end
15
-
16
-
17
- def load_builtin_words
18
- builtin_words = {
19
- 'en' => 'fixtures/en',
20
- 'de' => 'fixtures/de',
21
- 'es' => 'fixtures/es',
22
- 'fr' => 'fixtures/fr',
23
- 'it' => 'fixtures/it',
24
- 'pt' => 'fixtures/pt',
25
- 'ro' => 'fixtures/ro'
26
- }
27
-
28
- load_words( builtin_words, SportDb.config_path )
29
- end
30
-
31
-
32
- def load_words( h, include_path )
33
- @lang = 'en' # make default lang english/en
34
- @words = {} # resets fixtures
35
- @cache = {} # reset cached values
36
-
37
- h.each_with_index do |(key,value),i|
38
- name = value
39
- path = "#{include_path}/#{name}.yml"
40
- logger.debug( "loading words #{key} (#{i+1}/#{h.size}) in '#{name}' (#{path})..." )
41
- @words[ key ] = YAML.load( File.read_utf8( path ))
42
- end
43
-
44
- @classifier = TextUtils::Classifier.new
45
- @words.each_with_index do |(key,value),i|
46
- logger.debug "train classifier for #{key} (#{i+1}/#{@words.size})"
47
- @classifier.train( key, value )
48
- end
49
-
50
- @classifier.dump # for debugging dump all words
51
- end
52
-
53
- def classify( text )
54
- @classifier.classify( text )
55
- end
56
-
57
- def classify_file( path )
58
- @classifier.classify_file( path )
59
- end
60
-
61
- def lang=(value)
62
- logger.debug "setting lang to #{value}"
63
-
64
- if @lang != value
65
-
66
- ### todo: make reset cached values into method/function for reuse (see load_words)
67
- # reset cached values on language change
68
- logger.debug "reseting cached lang values (lang changed from #{@lang} to #{value})"
69
-
70
- @cache = {}
71
- end
72
-
73
- @lang = value
74
-
75
- end
76
-
77
-
78
- def group
79
- @cache[ :group ] ||= group_getter
80
- end
81
-
82
- def round
83
- @cache[ :round ] ||= round_getter
84
- end
85
-
86
- def knockout_round
87
- @cache[ :knockout_round ] ||= knockout_round_getter
88
- end
89
-
90
- def leg1
91
- @cache[ :leg1 ] ||= leg1_getter
92
- end
93
-
94
- def leg2
95
- @cache[ :leg2 ] ||= leg2_getter
96
- end
97
-
98
-
99
-
100
- def regex_group
101
- @cache [ :regex_group ] ||= regex_group_getter
102
- end
103
-
104
- def regex_round
105
- @cache[ :regex_round ] ||= regex_round_getter
106
- end
107
-
108
- def regex_knockout_round
109
- @cache[ :regex_knockout_round ] ||= regex_knockout_round_getter
110
- end
111
-
112
- def regex_leg1
113
- @cache[ :regex_leg1 ] ||= regex_leg1_getter
114
- end
115
-
116
- def regex_leg2
117
- @cache[ :regex_leg2 ] ||= regex_leg2_getter
118
- end
119
-
120
- private
121
- def group_getter
122
- h = @words[ lang ]
123
- values = "" # NB: always construct a new string (do NOT use a reference to hash value)
124
- values << h['group']
125
- values
126
- end
127
-
128
- def round_getter
129
- # e.g. Spieltag|Runde|Achtelfinale|Viertelfinale|Halbfinale|Finale
130
-
131
- ## fix/todo:
132
- ## sort by length first - to allow best match e.g.
133
- ## 3rd place play-off instead of Play-off ?? etc. - why? why not?
134
-
135
- h = @words[ lang ]
136
- values = "" # NB: always construct a new string (do NOT use a reference to hash value)
137
- values << h['round']
138
-
139
- ### add knockout rounds values too
140
- values << "|" << h['round32']
141
- values << "|" << h['round16']
142
- values << "|" << h['quarterfinals']
143
- values << "|" << h['semifinals']
144
- values << "|" << h['fifthplace'] if h['fifthplace'] # nb: allow empty/is optional!!
145
- values << "|" << h['thirdplace']
146
- values << "|" << h['final']
147
- values << "|" << h['playoffs'] if h['playoffs'] # nb: allow empty/is optional!!
148
- values
149
- end
150
-
151
- def leg1_getter
152
- h = @words[ lang ]
153
- values = "" # NB: always construct a new string (do NOT use a reference to hash value)
154
- values << h['leg1']
155
- values
156
- end
157
-
158
- def leg2_getter
159
- h = @words[ lang ]
160
- values = "" # NB: always construct a new string (do NOT use a reference to hash value)
161
- values << h['leg2']
162
- values
163
- end
164
-
165
- def knockout_round_getter
166
- h = @words[ lang ]
167
- values = "" # NB: always construct a new string (do NOT use a reference to hash value)
168
- values << h['round32']
169
- values << "|" << h['round16']
170
- values << "|" << h['quarterfinals']
171
- values << "|" << h['semifinals']
172
- values << "|" << h['fifthplace'] if h['fifthplace'] # nb: allow empty/is optional!!
173
- values << "|" << h['thirdplace']
174
- values << "|" << h['final']
175
- values << "|" << h['playoffs'] if h['playoffs'] # nb: allow empty/is optional!!
176
- values
177
- end
178
-
179
- def regex_group_getter
180
- ## todo: escape for regex?
181
- ## NB: let's ignore case (that is, UPCASE,downcase); always use /i flag
182
- /#{group}/i
183
- end
184
-
185
- def regex_round_getter
186
- ## todo: escape for regex?
187
- ## todo: sort by length - biggest words go first? does regex match biggest word automatically?? - check
188
- ## todo/fix: make - optional e.g. convert to ( |-) or better [ \-] ??
189
- ## NB: let's ignore case (that is, UPCASE,downcase); always use /i flag
190
- /#{round}/i
191
- end
192
-
193
- def regex_knockout_round_getter
194
- ## todo: escape for regex?
195
- ## todo: sort by length - biggest words go first? does regex match biggest word automatically?? - check
196
- ## todo/fix: make - optional e.g. convert to ( |-) or better [ \-] ??
197
- ## NB: let's ignore case (that is, UPCASE,downcase); always use /i flag
198
- /#{knockout_round}/i
199
- end
200
-
201
- def regex_leg1_getter
202
- ## todo: escape for regex?
203
- ## NB: let's ignore case (that is, UPCASE,downcase); always use /i flag
204
- /#{leg1}/i
205
- end
206
-
207
- def regex_leg2_getter
208
- ## todo: escape for regex?
209
- ## NB: let's ignore case (that is, UPCASE,downcase); always use /i flag
210
- /#{leg2}/i
211
- end
212
-
213
- end # class Lang
214
-
215
-
216
- end # module SportDb
@@ -1,31 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
-
5
- module Matcher
6
-
7
- include WorldDb::Matcher
8
-
9
- def match_leagues_for_country( name, &blk )
10
- match_xxx_for_country( name, 'leagues', &blk )
11
- end
12
-
13
- def match_teams_for_country( name, &blk )
14
- match_xxx_for_country( name, 'teams', &blk )
15
- end
16
-
17
- def match_clubs_for_country( name, &blk )
18
- match_xxx_for_country( name, 'clubs', &blk )
19
- end
20
-
21
- def match_players_for_country( name, &blk )
22
- match_xxx_for_country( name, 'players', &blk )
23
- end
24
-
25
- def match_stadiums_for_country( name, &blk )
26
- match_xxx_for_country( name, 'stadiums', &blk )
27
- end
28
-
29
- end # module Matcher
30
-
31
- end # module SportDb
@@ -1,106 +0,0 @@
1
- module SportDb
2
- module Model
3
-
4
- class Assoc < ActiveRecord::Base
5
-
6
- has_many :parent_assoc_assocs, class_name: 'AssocAssoc', foreign_key: 'assoc2_id'
7
- ## child_assocs - use child_assocs? - (direct) member/child assocs instead of member?
8
- has_many :member_assoc_assocs, class_name: 'AssocAssoc', foreign_key: 'assoc1_id'
9
-
10
-
11
- ## note: split member_assocs into two sets (into national=true and national=false)
12
- # e.g. fifa has six member confederations (non-national) and 216 national assocs
13
- if ActiveRecord::VERSION::MAJOR == 3
14
- has_many :all_assocs, class_name: 'Assoc', :source => :assoc2, :through => :member_assoc_assocs
15
- has_many :sub_assocs, class_name: 'Assoc', :source => :assoc2, :through => :member_assoc_assocs, conditions: { national: false }
16
- has_many :national_assocs, class_name: 'Assoc', :source => :assoc2, :through => :member_assoc_assocs, conditions: { national: true }
17
- else
18
- ## note: includes all member (sub assocs + national assocs) - rename to member_assocs?
19
- has_many :all_assocs, class_name: 'Assoc', :source => :assoc2, :through => :member_assoc_assocs
20
- ## use zone/region as name instead of sub ( for confederatons,zones,etc.)
21
- has_many :sub_assocs, -> { where( national: false ) }, class_name: 'Assoc', :source => :assoc2, :through => :member_assoc_assocs
22
- has_many :national_assocs, -> { where( national: true ) }, class_name: 'Assoc', :source => :assoc2, :through => :member_assoc_assocs
23
- end
24
-
25
- ## for now can have more than one (direct) parent assoc
26
- ## e.g. Africa Fed and Arab League Fed
27
- has_many :parent_assocs, class_name: 'Assoc', :source => :assoc1, :through => :parent_assoc_assocs
28
-
29
- # assoc only can have one direct team for now (uses belongs_to on other side)
30
- # has_one :team
31
-
32
-
33
- def self.create_or_update_from_values( new_attributes, values )
34
-
35
- ## fix: add/configure logger for ActiveRecord!!!
36
- logger = LogUtils::Logger.root
37
-
38
- assoc_keys = [] # by default no association (e.g. fifa,uefa,etc.)
39
-
40
- ## check optional values
41
- values.each_with_index do |value, index|
42
- if value =~ /^(18|19|20)[0-9]{2}$/ ## assume founding year -- allow 18|19|20
43
- ## logger.info " founding/opening year #{value}"
44
- new_attributes[ :since ] = value.to_i
45
- elsif value =~ /\/{2}/ # assume it's an address line e.g. xx // xx
46
- logger.info " found address line #{value}"
47
- ## new_attributes[ :address ] = value
48
- elsif value =~ /^(?:[a-z]{2}\.)?wikipedia:/ # assume it's wikipedia e.g. [es.]wikipedia:
49
- logger.info " found wikipedia line #{value}; skipping for now"
50
- elsif value =~ /(^www\.)|(\.com$)/ # FIX: !!!! use a better matcher not just www. and .com
51
- new_attributes[ :web ] = value
52
- ## elsif value =~ /^[a-z]{2}$/ ## assume two-letter country key e.g. at,de,mx,etc.
53
- ## ## fix: allow country letter with three e.g. eng,sco,wal,nir, etc. !!!
54
- ## value_country = Country.find_by_key!( value )
55
- ## new_attributes[ :country_id ] = value_country.id
56
- elsif value =~ /^[a-z]{2}$/ ## assume two-letter country key e.g. at,de,mx,etc.
57
- ## fix: allow country letter with three e.g. eng,sco,wal,nir, etc. !!!
58
- ## fix: if country does NOT match / NOT found - just coninue w/ next match!!!!
59
- # - just issue an error/warn do NOT crash
60
- value_country = Country.find_by_key!( value )
61
- new_attributes[ :country_id ] = value_country.id
62
- ## note: if country present - assume it's a national assoc, thus, set flag to true
63
- new_attributes[ :national ] = true
64
- elsif value =~ /^[a-z|]+$/ ## looks like a tag list e.g. fifa|uefa or fifa|caf or ocf?
65
- logger.info " trying adding assocs using keys >#{value}<"
66
- assoc_keys = value.split('|')
67
- else
68
- ## todo: assume title2 ??
69
- # issue warning: unknown type for value
70
- logger.warn "unknown type for value >#{value}< - key #{new_attributes[:key]}"
71
- end
72
- end
73
-
74
- rec = Assoc.find_by_key( new_attributes[ :key ] )
75
- if rec.present?
76
- logger.debug "update Assoc #{rec.id}-#{rec.key}:"
77
- else
78
- logger.debug "create Assoc:"
79
- rec = Assoc.new
80
- end
81
-
82
- logger.debug new_attributes.to_json
83
-
84
- rec.update_attributes!( new_attributes )
85
-
86
- unless assoc_keys.empty?
87
- ## add team to assocs
88
- assoc_keys.each do |assoc_key|
89
- assoc = Assoc.find_by_key!( assoc_key )
90
- logger.debug " adding assoc to assoc >#{assoc.title}<"
91
-
92
- ### todo/fix: how can we delete assoc_assocs? for now only update n create
93
- assoc_assoc = AssocAssoc.where( assoc1_id: assoc.id, assoc2_id: rec.id ).first
94
- if assoc_assoc.nil? ## create if does NOT exist yet
95
- AssocAssoc.create!( assoc1_id: assoc.id, assoc2_id: rec.id )
96
- end
97
- end
98
- end
99
-
100
- end # create_or_update_from_values
101
-
102
- end # class Assoc
103
-
104
-
105
- end # module Model
106
- end # module SportDb