sportdb-formats 1.0.5 → 1.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/Manifest.txt +8 -11
  3. data/Rakefile +1 -1
  4. data/lib/sportdb/formats.rb +19 -0
  5. data/lib/sportdb/formats/country/country_index.rb +2 -2
  6. data/lib/sportdb/formats/event/event_index.rb +141 -0
  7. data/lib/sportdb/formats/event/event_reader.rb +183 -0
  8. data/lib/sportdb/formats/league/league_index.rb +22 -18
  9. data/lib/sportdb/formats/league/league_outline_reader.rb +27 -7
  10. data/lib/sportdb/formats/league/league_reader.rb +7 -1
  11. data/lib/sportdb/formats/match/mapper.rb +63 -63
  12. data/lib/sportdb/formats/match/mapper_teams.rb +1 -1
  13. data/lib/sportdb/formats/match/match_parser.rb +141 -193
  14. data/lib/sportdb/formats/match/match_parser_csv.rb +169 -25
  15. data/lib/sportdb/formats/match/match_status_parser.rb +86 -0
  16. data/lib/sportdb/formats/name_helper.rb +4 -1
  17. data/lib/sportdb/formats/package.rb +57 -9
  18. data/lib/sportdb/formats/parser_helper.rb +11 -2
  19. data/lib/sportdb/formats/score/score_formats.rb +19 -0
  20. data/lib/sportdb/formats/score/score_parser.rb +10 -2
  21. data/lib/sportdb/formats/season_utils.rb +0 -11
  22. data/lib/sportdb/formats/structs/group.rb +5 -12
  23. data/lib/sportdb/formats/structs/match.rb +7 -1
  24. data/lib/sportdb/formats/structs/round.rb +6 -13
  25. data/lib/sportdb/formats/structs/season.rb +114 -45
  26. data/lib/sportdb/formats/structs/standings.rb +30 -9
  27. data/lib/sportdb/formats/structs/team.rb +8 -2
  28. data/lib/sportdb/formats/team/club_index.rb +13 -11
  29. data/lib/sportdb/formats/team/club_index_history.rb +138 -0
  30. data/lib/sportdb/formats/team/club_reader_history.rb +203 -0
  31. data/lib/sportdb/formats/team/club_reader_props.rb +2 -3
  32. data/lib/sportdb/formats/version.rb +2 -2
  33. data/test/helper.rb +48 -81
  34. data/test/test_club_index_history.rb +107 -0
  35. data/test/test_club_reader_history.rb +212 -0
  36. data/test/test_country_reader.rb +2 -2
  37. data/test/test_datafile_package.rb +1 -1
  38. data/test/test_match_status_parser.rb +49 -0
  39. data/test/test_regex.rb +25 -7
  40. data/test/test_scores.rb +2 -0
  41. data/test/test_season.rb +68 -19
  42. metadata +12 -15
  43. data/test/test_conf.rb +0 -65
  44. data/test/test_csv_match_parser.rb +0 -114
  45. data/test/test_csv_match_parser_utils.rb +0 -20
  46. data/test/test_match_auto.rb +0 -72
  47. data/test/test_match_auto_champs.rb +0 -45
  48. data/test/test_match_auto_euro.rb +0 -37
  49. data/test/test_match_auto_worldcup.rb +0 -61
  50. data/test/test_match_champs.rb +0 -27
  51. data/test/test_match_eng.rb +0 -26
  52. data/test/test_match_euro.rb +0 -27
  53. data/test/test_match_worldcup.rb +0 -27
@@ -6,8 +6,8 @@ module SportDb
6
6
  module Formats
7
7
 
8
8
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
9
- MINOR = 0
10
- PATCH = 5
9
+ MINOR = 1
10
+ PATCH = 3
11
11
  VERSION = [MAJOR,MINOR,PATCH].join('.')
12
12
 
13
13
  def self.version
@@ -1,5 +1,6 @@
1
1
  ## note: use the local version of gems
2
2
  $LOAD_PATH.unshift( File.expand_path( '../date-formats/lib' ))
3
+ $LOAD_PATH.unshift( File.expand_path( '../sportdb-langs/lib' ))
3
4
 
4
5
 
5
6
  ## minitest setup
@@ -54,12 +55,56 @@ TXT
54
55
  = England
55
56
 
56
57
  Chelsea FC
57
- Arsenal FC
58
58
  Tottenham Hotspur
59
59
  West Ham United
60
60
  Crystal Palace
61
- Manchester United
62
- Manchester City
61
+
62
+ ### note add move entires for testing club name history
63
+ Manchester United FC
64
+ | Manchester United
65
+ | Newton Heath FC
66
+
67
+ Manchester City FC
68
+ | Manchester City
69
+ | Ardwick FC
70
+
71
+ Arsenal FC
72
+ | The Arsenal FC
73
+ | Woolwich Arsenal FC
74
+ | Royal Arsenal FC
75
+
76
+ Gateshead FC
77
+ | South Shields FC
78
+
79
+ Sheffield Wednesday
80
+ | The Wednesday FC
81
+
82
+ Port Vale FC
83
+ | Burslem Port Vale FC
84
+
85
+ Chesterfield FC
86
+ | Chesterfield Town FC
87
+
88
+ Birmingham FC
89
+ | Small Heath FC
90
+
91
+ Burton Swifts FC
92
+ Burton Wanderers FC
93
+ Burton United FC
94
+
95
+ Blackpool FC
96
+ South Shore FC
97
+
98
+ Glossop FC
99
+ | Glossop North End FC
100
+
101
+ Walsall FC
102
+ | Walsall Town Swifts FC
103
+
104
+
105
+ Newcastle West End FC
106
+ Newcastle East End FC
107
+ Newcastle United FC
63
108
  TXT
64
109
 
65
110
  index = ClubIndex.new
@@ -82,81 +127,3 @@ end # module SportDb
82
127
 
83
128
 
84
129
 
85
- ################
86
- ## helper
87
-
88
- def parse_auto_conf( txt, lang: 'en', start: nil )
89
- start = start ? start : Date.new( 2017, 7, 1 )
90
-
91
- SportDb::Import.config.lang = lang
92
-
93
- parser = SportDb::AutoConfParser.new( txt, start )
94
- parser.parse
95
- end
96
-
97
- def parse_conf( txt )
98
- parser = SportDb::ConfParser.new( txt )
99
- parser.parse
100
- end
101
-
102
-
103
- ## note: json always returns hash tables with string keys (not symbols),
104
- ## thus, always stringify keys before comparing!!!!
105
- class Object
106
- def deep_stringify_keys
107
- if self.is_a? Hash
108
- self.reduce({}) {|memo,(k,v)| memo[k.to_s] = v.deep_stringify_keys; memo }
109
- elsif self.is_a? Array
110
- self.reduce([]) {|memo,v | memo << v.deep_stringify_keys; memo }
111
- else
112
- self
113
- end
114
- end
115
- end
116
-
117
-
118
- def read_blocks( path )
119
- txt = File.open( path, 'r:utf-8' ).read
120
-
121
- blocks = []
122
- buf = String.new('')
123
- txt.each_line do |line|
124
- if line =~ /^[ ]*
125
- ([>]{3,} |
126
- [<]{3,})
127
- [ ]*
128
- $/x ## three or more markers
129
- blocks << buf
130
- buf = String.new('')
131
- else
132
- buf << line
133
- end
134
- end
135
- blocks << buf
136
- blocks
137
- end
138
-
139
-
140
- def parse_json( str )
141
- ## note: allow empty string; fall back to empty hash
142
- if str.strip.empty?
143
- {}
144
- else
145
- JSON.parse( str )
146
- end
147
- end
148
-
149
- def read_test( path )
150
- blocks = read_blocks( "#{SportDb::Test.data_dir}/football.txt/#{path}" )
151
-
152
- if blocks.size == 2
153
- [blocks[0], parse_json( blocks[1] )]
154
- elsif blocks.size == 3
155
- ## note: returned in different order
156
- ## optional option block that comes first returned last!
157
- [blocks[1], parse_json( blocks[2] ), blocks[0]]
158
- else
159
- puts "!! ERROR: expected two or three text blocks in >#{path}<; got #{blocks.size}"
160
- exit 1
161
- end
162
- end
@@ -0,0 +1,107 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_club_index_history.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestClubHistoryIndex < MiniTest::Test
11
+
12
+ def test_eng
13
+ txt =<<TXT
14
+ = England
15
+
16
+ ## note: use history log by season (instead of by year) - why? why not?
17
+ ##
18
+ ## note/warn/remember !! a line starting with arrow (=>)
19
+ ## will get turned into a heading 1!!!
20
+ ## as an ascii-alternative to ⇒ use >> or -> or ??? - why? why not?
21
+
22
+ == 1930/1
23
+ MOVE South Shields FC, South Shields ⇒ Gateshead FC, Gateshead
24
+
25
+
26
+ == 1929/30
27
+ RENAME The Wednesday FC, Sheffield ⇒ Sheffield Wednesday
28
+
29
+ == 1927/8
30
+ RENAME The Arsenal FC, London ⇒ Arsenal FC
31
+
32
+
33
+ == 1914/5
34
+ RENAME Woolwich Arsenal FC, London ⇒ The Arsenal FC
35
+
36
+
37
+ == 1911/2
38
+ REFORM Burslem Port Vale FC, Burslem ⇒ Port Vale FC, Stoke-on-Trent
39
+ ## the towns of Burslem having been merged in 1910 with the towns of Fenton, Hanley,
40
+ ## Longton, Stoke-upon-Trent and Tunstall as the city of Stoke-on-Trent
41
+
42
+
43
+ == 1909/10
44
+ RENAME Chesterfield Town FC, Chesterfield ⇒ Chesterfield FC
45
+
46
+
47
+ == 1905/6
48
+ RENAME Chesterfield FC, Chesterfield ⇒ Chesterfield Town FC
49
+ Small Heath FC, Birmingham ⇒ Birmingham FC
50
+
51
+ == 1902/3
52
+ REFORM Newton Heath FC, Manchester ⇒ Manchester United
53
+
54
+ == 1901/2
55
+ MERGE Burton Swifts FC, Burton-upon-Trent
56
+ Burton Wanderers FC, Burton-upon-Trent
57
+ ⇒ Burton United FC
58
+
59
+ BANKRUPT Newton Heath FC, Manchester
60
+
61
+
62
+ == 1899/00
63
+ MERGE Blackpool FC, Blackpool
64
+ South Shore FC, Blackpool
65
+ ⇒ Blackpool FC
66
+
67
+ == 1898/9
68
+ RENAME Glossop North End FC, Glossop ⇒ Glossop FC
69
+
70
+
71
+ == 1895/6
72
+ RENAME Walsall Town Swifts FC, Walsall ⇒ Walsall FC
73
+
74
+
75
+ == 1894/5
76
+ REFORM Ardwick FC, Manchester ⇒ Manchester City FC
77
+
78
+ == 1893/4
79
+ BANKRUPT Ardwick FC, Manchester
80
+
81
+ MERGE Newcastle West End FC, Newcastle-upon-Tyne
82
+ Newcastle East End FC, Newcastle-upon-Tyne
83
+ ⇒ Newcastle United FC
84
+
85
+ == 1892/3
86
+ RENAME Royal Arsenal FC, London ⇒ Woolwich Arsenal FC
87
+ TXT
88
+
89
+ recs = SportDb::Import::ClubHistoryReader.parse( txt )
90
+
91
+ history = SportDb::Import::ClubHistoryIndex.new
92
+ history.add( recs )
93
+
94
+ pp history.errors
95
+ pp history.mappings
96
+
97
+ # [[1927/28, ["RENAME", [["The Arsenal FC, London", "eng"], ["Arsenal FC", "eng"]]]],
98
+ # [1914/15, ["RENAME", [["Woolwich Arsenal FC, London", "eng"], ["The Arsenal FC", "eng"]]]],
99
+ # [1892/93, ["RENAME", [["Royal Arsenal FC, London", "eng"], ["Woolwich Arsenal FC", "eng"]]]]],
100
+ assert_equal 'Arsenal FC', history.find_name_by( name: 'Arsenal FC', season: '2000/1' )
101
+ assert_equal 'Arsenal FC', history.find_name_by( name: 'Arsenal FC', season: '1927/8' )
102
+ assert_equal 'The Arsenal FC', history.find_name_by( name: 'Arsenal FC', season: '1926/7' )
103
+ assert_equal 'Woolwich Arsenal FC', history.find_name_by( name: 'Arsenal FC', season: '1913/4' )
104
+ assert_equal 'Royal Arsenal FC', history.find_name_by( name: 'Arsenal FC', season: '1891/2' )
105
+ end
106
+
107
+ end # class TestClubHistoryIndex
@@ -0,0 +1,212 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_club_reader_history.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+
11
+ class TestClubHistoryReader < MiniTest::Test
12
+
13
+ def test_parse_eng
14
+ txt =<<TXT
15
+ = England
16
+
17
+ ## note: use history log by season (instead of by year) - why? why not?
18
+ ##
19
+ ## note/warn/remember !! a line starting with arrow (=>)
20
+ ## will get turned into a heading 1!!!
21
+ ## as an ascii-alternative to ⇒ use >> or -> or ??? - why? why not?
22
+
23
+
24
+
25
+ == 1958/9
26
+ RENAME Scunthorpe & Lindsey United FC, Scunthorpe ⇒ Scunthorpe United FC
27
+
28
+ == 1946/7
29
+ RENAME Clapton Orient FC, London ⇒ Leyton Orient FC
30
+
31
+ == 1945/6
32
+ RENAME Birmingham FC, Birmingham ⇒ Birmingham City FC
33
+
34
+ == 1930/1
35
+ MOVE South Shields FC, South Shields ⇒ Gateshead FC, Gateshead
36
+
37
+
38
+
39
+ == 1929/30
40
+ RENAME The Wednesday FC, Sheffield ⇒ Sheffield Wednesday
41
+
42
+ == 1927/8
43
+ RENAME The Arsenal FC, London ⇒ Arsenal FC
44
+
45
+ == 1925/6
46
+ RENAME Millwall Athletic FC, London ⇒ Millwall FC
47
+ Stoke FC, Stoke-on-Trent ⇒ Stoke City FC
48
+
49
+ MERGE Rotherham County FC, Rotherham
50
+ Rotherham Town FC, Rotherham
51
+ ⇒ Rotherham United FC
52
+
53
+ == 1914/5
54
+ RENAME Woolwich Arsenal FC, London ⇒ The Arsenal FC
55
+
56
+
57
+ == 1911/2
58
+ REFORM Burslem Port Vale FC, Burslem ⇒ Port Vale FC, Stoke-on-Trent
59
+ ## the towns of Burslem having been merged in 1910 with the towns of Fenton, Hanley,
60
+ ## Longton, Stoke-upon-Trent and Tunstall as the city of Stoke-on-Trent
61
+
62
+
63
+ == 1909/10
64
+ RENAME Chesterfield Town FC, Chesterfield ⇒ Chesterfield FC
65
+
66
+
67
+ == 1905/6
68
+ RENAME Chesterfield FC, Chesterfield ⇒ Chesterfield Town FC
69
+ Small Heath FC, Birmingham ⇒ Birmingham FC
70
+
71
+ == 1902/3
72
+ REFORM Newton Heath FC, Manchester ⇒ Manchester United
73
+
74
+ == 1901/2
75
+ MERGE Burton Swifts FC, Burton-upon-Trent
76
+ Burton Wanderers FC, Burton-upon-Trent
77
+ ⇒ Burton United FC
78
+
79
+ BANKRUPT Newton Heath FC, Manchester
80
+
81
+
82
+ == 1899/00
83
+ RENAME Barnsley St. Peter's FC, Barnsley ⇒ Barnsley FC
84
+
85
+ MERGE Blackpool FC, Blackpool
86
+ South Shore FC, Blackpool
87
+ ⇒ Blackpool FC
88
+
89
+ == 1898/9
90
+ RENAME Glossop North End FC, Glossop ⇒ Glossop FC
91
+
92
+
93
+ == 1895/6
94
+ RENAME Walsall Town Swifts FC, Walsall ⇒ Walsall FC
95
+
96
+
97
+ == 1894/5
98
+ REFORM Ardwick FC, Manchester ⇒ Manchester City FC
99
+
100
+ == 1893/4
101
+ BANKRUPT Ardwick FC, Manchester
102
+
103
+ MERGE Newcastle West End FC, Newcastle-upon-Tyne
104
+ Newcastle East End FC, Newcastle-upon-Tyne
105
+ ⇒ Newcastle United FC
106
+
107
+ == 1892/3
108
+ RENAME Royal Arsenal FC, London ⇒ Woolwich Arsenal FC
109
+ TXT
110
+
111
+ recs = SportDb::Import::ClubHistoryReader.parse( txt )
112
+
113
+ pp recs
114
+
115
+ exp = [["RENAME", "1958/59",
116
+ ["Scunthorpe & Lindsey United FC, Scunthorpe", "eng"],
117
+ ["Scunthorpe United FC", "eng"]],
118
+ ["RENAME", "1946/47",
119
+ ["Clapton Orient FC, London", "eng"],
120
+ ["Leyton Orient FC", "eng"]],
121
+ ["RENAME", "1945/46",
122
+ ["Birmingham FC, Birmingham", "eng"],
123
+ ["Birmingham City FC", "eng"]],
124
+ ["MOVE", "1930/31",
125
+ ["South Shields FC, South Shields", "eng"],
126
+ ["Gateshead FC, Gateshead", "eng"]],
127
+ ["RENAME",
128
+ "1929/30",
129
+ ["The Wednesday FC, Sheffield", "eng"],
130
+ ["Sheffield Wednesday", "eng"]],
131
+ ["RENAME",
132
+ "1927/28",
133
+ ["The Arsenal FC, London", "eng"],
134
+ ["Arsenal FC", "eng"]],
135
+ ["RENAME",
136
+ "1925/26",
137
+ ["Millwall Athletic FC, London", "eng"],
138
+ ["Millwall FC", "eng"]],
139
+ ["RENAME",
140
+ "1925/26",
141
+ ["Stoke FC, Stoke-on-Trent", "eng"],
142
+ ["Stoke City FC", "eng"]],
143
+ ["MERGE",
144
+ "1925/26",
145
+ [["Rotherham County FC, Rotherham", "eng"],
146
+ ["Rotherham Town FC, Rotherham", "eng"]],
147
+ ["Rotherham United FC", "eng"]],
148
+ ["RENAME",
149
+ "1914/15",
150
+ ["Woolwich Arsenal FC, London", "eng"],
151
+ ["The Arsenal FC", "eng"]],
152
+ ["REFORM",
153
+ "1911/12",
154
+ ["Burslem Port Vale FC, Burslem", "eng"],
155
+ ["Port Vale FC, Stoke-on-Trent", "eng"]],
156
+ ["RENAME",
157
+ "1909/10",
158
+ ["Chesterfield Town FC, Chesterfield", "eng"],
159
+ ["Chesterfield FC", "eng"]],
160
+ ["RENAME",
161
+ "1905/06",
162
+ ["Chesterfield FC, Chesterfield", "eng"],
163
+ ["Chesterfield Town FC", "eng"]],
164
+ ["RENAME",
165
+ "1905/06",
166
+ ["Small Heath FC, Birmingham", "eng"],
167
+ ["Birmingham FC", "eng"]],
168
+ ["REFORM",
169
+ "1902/03",
170
+ ["Newton Heath FC, Manchester", "eng"],
171
+ ["Manchester United", "eng"]],
172
+ ["MERGE",
173
+ "1901/02",
174
+ [["Burton Swifts FC, Burton-upon-Trent", "eng"],
175
+ ["Burton Wanderers FC, Burton-upon-Trent", "eng"]],
176
+ ["Burton United FC", "eng"]],
177
+ ["BANKRUPT", "1901/02", ["Newton Heath FC, Manchester", "eng"]],
178
+ ["RENAME",
179
+ "1899/00",
180
+ ["Barnsley St. Peter's FC, Barnsley", "eng"],
181
+ ["Barnsley FC", "eng"]],
182
+ ["MERGE",
183
+ "1899/00",
184
+ [["Blackpool FC, Blackpool", "eng"], ["South Shore FC, Blackpool", "eng"]],
185
+ ["Blackpool FC", "eng"]],
186
+ ["RENAME",
187
+ "1898/99",
188
+ ["Glossop North End FC, Glossop", "eng"],
189
+ ["Glossop FC", "eng"]],
190
+ ["RENAME",
191
+ "1895/96",
192
+ ["Walsall Town Swifts FC, Walsall", "eng"],
193
+ ["Walsall FC", "eng"]],
194
+ ["REFORM",
195
+ "1894/95",
196
+ ["Ardwick FC, Manchester", "eng"],
197
+ ["Manchester City FC", "eng"]],
198
+ ["BANKRUPT", "1893/94", ["Ardwick FC, Manchester", "eng"]],
199
+ ["MERGE",
200
+ "1893/94",
201
+ [["Newcastle West End FC, Newcastle-upon-Tyne", "eng"],
202
+ ["Newcastle East End FC, Newcastle-upon-Tyne", "eng"]],
203
+ ["Newcastle United FC", "eng"]],
204
+ ["RENAME",
205
+ "1892/93",
206
+ ["Royal Arsenal FC, London", "eng"],
207
+ ["Woolwich Arsenal FC", "eng"]]]
208
+
209
+ assert_equal exp, recs
210
+ end
211
+
212
+ end # class TestClubHistoryReader