sportdb-formats 2.0.1 → 2.1.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/Manifest.txt +2 -19
- data/Rakefile +2 -7
- data/bin/fbchk +166 -0
- data/lib/sportdb/formats/quick_match_linter.rb +195 -0
- data/lib/sportdb/formats/version.rb +2 -2
- data/lib/sportdb/formats.rb +10 -269
- metadata +10 -82
- data/lib/sportdb/formats/country/country_reader.rb +0 -142
- data/lib/sportdb/formats/csv/goal.rb +0 -192
- data/lib/sportdb/formats/csv/goal_parser_csv.rb +0 -28
- data/lib/sportdb/formats/csv/match_parser_csv.rb +0 -490
- data/lib/sportdb/formats/csv/match_status_parser.rb +0 -90
- data/lib/sportdb/formats/datafile.rb +0 -59
- data/lib/sportdb/formats/event/event_reader.rb +0 -119
- data/lib/sportdb/formats/ground/ground_reader.rb +0 -289
- data/lib/sportdb/formats/league/league_outline_reader.rb +0 -176
- data/lib/sportdb/formats/league/league_reader.rb +0 -152
- data/lib/sportdb/formats/match/conf_parser.rb +0 -132
- data/lib/sportdb/formats/match/match_parser.rb +0 -733
- data/lib/sportdb/formats/search/sport.rb +0 -372
- data/lib/sportdb/formats/search/structs.rb +0 -116
- data/lib/sportdb/formats/search/world.rb +0 -157
- data/lib/sportdb/formats/team/club_reader.rb +0 -318
- data/lib/sportdb/formats/team/club_reader_history.rb +0 -203
- data/lib/sportdb/formats/team/club_reader_props.rb +0 -90
- data/lib/sportdb/formats/team/wiki_reader.rb +0 -108
data/lib/sportdb/formats.rb
CHANGED
@@ -1,17 +1,15 @@
|
|
1
1
|
## 3rd party gems
|
2
|
-
require 'sportdb/structs'
|
3
|
-
require 'sportdb/parser'
|
4
|
-
require '
|
2
|
+
# require 'sportdb/structs'
|
3
|
+
# require 'sportdb/parser'
|
4
|
+
require 'sportdb/quick'
|
5
5
|
|
6
6
|
|
7
7
|
require 'zip' ## todo/check: if zip is alreay included in a required module
|
8
8
|
|
9
9
|
|
10
|
-
## note - add cocos (code commons)
|
11
|
-
##
|
12
|
-
## pulls in read_csv & parse_csv etc.
|
13
|
-
require 'cocos'
|
14
10
|
|
11
|
+
## todo/check
|
12
|
+
## - logutils already added via quick!!
|
15
13
|
|
16
14
|
require 'logutils'
|
17
15
|
module SportDb
|
@@ -26,10 +24,8 @@ end
|
|
26
24
|
# our own code
|
27
25
|
require_relative 'formats/version' # let version always go first
|
28
26
|
|
29
|
-
require_relative 'formats/datafile'
|
30
|
-
require_relative 'formats/datafile_package'
|
31
27
|
require_relative 'formats/package'
|
32
|
-
|
28
|
+
require_relative 'formats/datafile_package'
|
33
29
|
|
34
30
|
|
35
31
|
## let's put test configuration in its own namespace / module
|
@@ -46,271 +42,16 @@ end # module SportDb
|
|
46
42
|
|
47
43
|
|
48
44
|
|
49
|
-
|
50
|
-
# define search services apis (move to its own gem later - why? why not?)
|
51
|
-
|
52
|
-
module SportDb
|
53
|
-
module Import
|
54
|
-
|
55
|
-
class Configuration
|
56
|
-
def world() @world ||= WorldSearch.new( countries: DummyCountrySearch.new ); end
|
57
|
-
def world=(world) @world = world; end
|
58
|
-
|
59
|
-
## todo/fix - add/move catalog here from sportdb-catalogs!!!
|
60
|
-
## def catalog() @catalog ||= Catalog.new; end
|
61
|
-
## def catalog(catalog) @catalog = catalog; end
|
62
|
-
end # class Configuration
|
63
|
-
|
64
|
-
## e.g. use config.catalog -- keep Import.catalog as a shortcut (for "read-only" access)
|
65
|
-
## def self.catalog() config.catalog; end
|
66
|
-
def self.world() config.world; end
|
67
|
-
|
68
|
-
## lets you use
|
69
|
-
## SportDb::Import.configure do |config|
|
70
|
-
## config.catalog_path = './catalog.db'
|
71
|
-
## end
|
72
|
-
def self.configure() yield( config ); end
|
73
|
-
def self.config() @config ||= Configuration.new; end
|
74
|
-
end # module Import
|
75
|
-
end # module SportDb
|
76
|
-
|
77
|
-
|
78
|
-
require_relative 'formats/search/world'
|
79
|
-
require_relative 'formats/search/sport'
|
80
|
-
require_relative 'formats/search/structs'
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
module Sports
|
85
|
-
## note: just forward to SportDb::Import configuration!!!!!
|
86
|
-
## keep Sports module / namespace "clean" - why? why not?
|
87
|
-
## that is, only include data structures (e.g. Match,League,etc) for now - why? why not?
|
88
|
-
def self.configure() yield( config ); end
|
89
|
-
def self.config() SportDb::Import.config; end
|
90
|
-
end # module Sports
|
91
|
-
|
92
|
-
|
93
|
-
###
|
94
|
-
# csv (tabular dataset) support / machinery
|
95
|
-
require_relative 'formats/csv/match_status_parser'
|
96
|
-
require_relative 'formats/csv/goal'
|
97
|
-
require_relative 'formats/csv/goal_parser_csv'
|
98
|
-
require_relative 'formats/csv/match_parser_csv'
|
99
|
-
|
100
|
-
|
101
|
-
### add convenience shortcut helpers
|
102
|
-
module Sports
|
103
|
-
class Match
|
104
|
-
def self.read_csv( path, headers: nil, filters: nil, converters: nil, sep: nil )
|
105
|
-
SportDb::CsvMatchParser.read( path,
|
106
|
-
headers: headers,
|
107
|
-
filters: filters,
|
108
|
-
converters: converters,
|
109
|
-
sep: sep )
|
110
|
-
end
|
111
|
-
|
112
|
-
def self.parse_csv( txt, headers: nil, filters: nil, converters: nil, sep: nil )
|
113
|
-
SportDb::CsvMatchParser.parse( txt,
|
114
|
-
headers: headers,
|
115
|
-
filters: filters,
|
116
|
-
converters: converters,
|
117
|
-
sep: sep )
|
118
|
-
end
|
119
|
-
end # class Match
|
120
|
-
end # module Sports
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
module SportDb
|
130
|
-
module Import
|
131
|
-
Season = ::Season ## add a convenience alias for top-level Season class
|
132
|
-
|
133
|
-
## add "old" convenience aliases for structs - why? why not?
|
134
|
-
## todo/check: just use include Sports !!!!
|
135
|
-
Country = ::Sports::Country
|
136
|
-
League = ::Sports::League
|
137
|
-
Group = ::Sports::Group
|
138
|
-
Round = ::Sports::Round
|
139
|
-
Match = ::Sports::Match
|
140
|
-
Matchlist = ::Sports::Matchlist
|
141
|
-
Goal = ::Sports::Goal
|
142
|
-
Team = ::Sports::Team
|
143
|
-
NationalTeam = ::Sports::NationalTeam
|
144
|
-
Club = ::Sports::Club
|
145
|
-
Standings = ::Sports::Standings
|
146
|
-
TeamUsage = ::Sports::TeamUsage
|
147
|
-
|
148
|
-
Ground = ::Sports::Ground
|
149
|
-
|
150
|
-
Player = ::Sports::Player
|
151
|
-
|
152
|
-
EventInfo = ::Sports::EventInfo
|
153
|
-
|
154
|
-
|
155
|
-
class Team
|
156
|
-
## add convenience lookup helper / method for name by season for now
|
157
|
-
## use clubs history - for now kept separate from struct - why? why not?
|
158
|
-
def name_by_season( season )
|
159
|
-
## note: returns / fallback to "regular" name if no records found in history
|
160
|
-
SportDb::Import.catalog.clubs_history.find_name_by( name: name, season: season ) || name
|
161
|
-
end
|
162
|
-
end # class Team
|
163
|
-
|
164
|
-
end # module Import
|
165
|
-
end # module SportDb
|
166
|
-
|
167
|
-
|
168
|
-
require_relative 'formats/match/match_parser'
|
169
|
-
require_relative 'formats/match/conf_parser'
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
require_relative 'formats/country/country_reader'
|
174
|
-
|
175
|
-
|
176
|
-
## add convenience helper
|
177
|
-
module SportDb
|
178
|
-
module Import
|
179
|
-
class Country
|
180
|
-
def self.read( path ) CountryReader.read( path ); end
|
181
|
-
def self.parse( txt ) CountryReader.parse( txt ); end
|
182
|
-
end # class Country
|
183
|
-
end # module Import
|
184
|
-
end # module SportDb
|
185
|
-
|
186
|
-
|
187
|
-
require_relative 'formats/league/league_reader'
|
188
|
-
require_relative 'formats/league/league_outline_reader'
|
189
|
-
|
190
|
-
##
|
191
|
-
## add convenience helper / short-cuts
|
192
|
-
module SportDb
|
193
|
-
module Import
|
194
|
-
class League
|
195
|
-
def self.read( path ) LeagueReader.read( path ); end
|
196
|
-
def self.parse( txt ) LeagueReader.parse( txt ); end
|
197
|
-
end # class League
|
198
|
-
end # module Import
|
199
|
-
end # module SportDb
|
200
|
-
|
201
|
-
|
202
|
-
require_relative 'formats/team/club_reader'
|
203
|
-
require_relative 'formats/team/club_reader_props'
|
204
|
-
require_relative 'formats/team/wiki_reader'
|
205
|
-
|
206
|
-
require_relative 'formats/team/club_reader_history'
|
207
|
-
require_relative 'formats/team/club_index_history'
|
208
|
-
|
209
|
-
|
210
|
-
###
|
211
|
-
# add convenience helpers / shortcuts
|
212
|
-
module SportDb
|
213
|
-
module Import
|
214
|
-
|
215
|
-
class Club
|
216
|
-
def self.read( path ) ClubReader.read( path ); end
|
217
|
-
def self.parse( txt ) ClubReader.parse( txt ); end
|
218
|
-
|
219
|
-
def self.read_props( path ) ClubPropsReader.read( path ); end
|
220
|
-
def self.parse_props( txt ) ClubPropsReader.parse( txt ); end
|
221
|
-
## todo/check: use ClubProps.read and ClubProps.parse convenience alternate shortcuts - why? why not?
|
222
|
-
end # class Club
|
223
|
-
|
224
|
-
end # module Import
|
225
|
-
end # module SportDb
|
226
|
-
|
227
|
-
|
228
|
-
require_relative 'formats/event/event_reader'
|
229
|
-
|
230
|
-
## add convenience helper
|
231
|
-
module SportDb
|
232
|
-
module Import
|
233
|
-
class EventInfo
|
234
|
-
def self.read( path ) EventInfoReader.read( path ); end
|
235
|
-
def self.parse( txt ) EventInfoReader.parse( txt ); end
|
236
|
-
end # class EventInfo
|
237
|
-
end # module Import
|
238
|
-
end # module SportDb
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
require_relative 'formats/ground/ground_reader'
|
45
|
+
require_relative 'formats/quick_match_linter'
|
243
46
|
|
244
47
|
|
48
|
+
# require_relative 'formats/team/club_reader_history'
|
49
|
+
# require_relative 'formats/team/club_index_history'
|
245
50
|
|
246
51
|
|
247
52
|
|
248
53
|
### auto-configure builtin lookups via catalog.db(s)
|
249
|
-
require 'sportdb/
|
250
|
-
|
251
|
-
|
252
|
-
module SportDb
|
253
|
-
module Import
|
254
|
-
|
255
|
-
class Configuration
|
256
|
-
## note: add more configs (open class), see sportdb-structs for original config!!!
|
257
|
-
|
258
|
-
###
|
259
|
-
# find a better name for setting - why? why not?
|
260
|
-
# how about catalogdb or ???
|
261
|
-
attr_reader :catalog_path
|
262
|
-
def catalog_path=(path)
|
263
|
-
@catalog_path = path
|
264
|
-
########
|
265
|
-
# reset database here to new path
|
266
|
-
CatalogDb::Metal::Record.database = path
|
267
|
-
|
268
|
-
## plus automagically set world search too (to use CatalogDb)
|
269
|
-
self.world = WorldSearch.new(
|
270
|
-
countries: CatalogDb::Metal::Country,
|
271
|
-
cities: CatalogDb::Metal::City,
|
272
|
-
)
|
273
|
-
|
274
|
-
@catalog_path
|
275
|
-
end
|
276
|
-
|
277
|
-
def catalog
|
278
|
-
@catalog ||= SportSearch.new(
|
279
|
-
leagues: CatalogDb::Metal::League,
|
280
|
-
national_teams: CatalogDb::Metal::NationalTeam,
|
281
|
-
clubs: CatalogDb::Metal::Club,
|
282
|
-
grounds: CatalogDb::Metal::Ground,
|
283
|
-
events: CatalogDb::Metal::EventInfo,
|
284
|
-
players: CatalogDb::Metal::Player, # note - via players.db !!!
|
285
|
-
)
|
286
|
-
end
|
287
|
-
|
288
|
-
###
|
289
|
-
# find a better name for setting - why? why not?
|
290
|
-
# how about playersdb or ???
|
291
|
-
attr_reader :players_path
|
292
|
-
def players_path=(path)
|
293
|
-
@players_path = path
|
294
|
-
########
|
295
|
-
# reset database here to new path
|
296
|
-
CatalogDb::Metal::PlayerRecord.database = path
|
297
|
-
|
298
|
-
@players_path
|
299
|
-
end
|
300
|
-
end # class Configuration
|
301
|
-
|
302
|
-
|
303
|
-
## e.g. use config.catalog -- keep Import.catalog as a shortcut (for "read-only" access)
|
304
|
-
def self.catalog() config.catalog; end
|
305
|
-
end # module Import
|
306
|
-
end # module SportDb
|
307
|
-
|
308
|
-
|
309
|
-
###
|
310
|
-
## add default/built-in catalog here - why? why not?
|
311
|
-
## todo/fix - set catalog_path on demand
|
312
|
-
## note: for now required for world search setup etc.
|
313
|
-
SportDb::Import.config.catalog_path = "#{FootballDb::Data.data_dir}/catalog.db"
|
54
|
+
require 'sportdb/search'
|
314
55
|
|
315
56
|
|
316
57
|
|
metadata
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb-formats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name: sportdb-
|
14
|
+
name: sportdb-search
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 0.0.1
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: 0.0.1
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name: sportdb-
|
28
|
+
name: sportdb-quick
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -38,62 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 0.2.0
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: sportdb-catalogs
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 1.2.2
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 1.2.2
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: date-formats
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 1.0.2
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: 1.0.2
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: cocos
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 0.4.0
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 0.4.0
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: logutils
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - ">="
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.6.1
|
90
|
-
type: :runtime
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - ">="
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.6.1
|
97
41
|
- !ruby/object:Gem::Dependency
|
98
42
|
name: rubyzip
|
99
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,7 +88,8 @@ dependencies:
|
|
144
88
|
version: '4.1'
|
145
89
|
description: sportdb-formats - sport.db format and text utilities
|
146
90
|
email: gerald.bauer@gmail.com
|
147
|
-
executables:
|
91
|
+
executables:
|
92
|
+
- fbchk
|
148
93
|
extensions: []
|
149
94
|
extra_rdoc_files:
|
150
95
|
- CHANGELOG.md
|
@@ -155,29 +100,12 @@ files:
|
|
155
100
|
- Manifest.txt
|
156
101
|
- README.md
|
157
102
|
- Rakefile
|
103
|
+
- bin/fbchk
|
158
104
|
- lib/sportdb/formats.rb
|
159
|
-
- lib/sportdb/formats/country/country_reader.rb
|
160
|
-
- lib/sportdb/formats/csv/goal.rb
|
161
|
-
- lib/sportdb/formats/csv/goal_parser_csv.rb
|
162
|
-
- lib/sportdb/formats/csv/match_parser_csv.rb
|
163
|
-
- lib/sportdb/formats/csv/match_status_parser.rb
|
164
|
-
- lib/sportdb/formats/datafile.rb
|
165
105
|
- lib/sportdb/formats/datafile_package.rb
|
166
|
-
- lib/sportdb/formats/event/event_reader.rb
|
167
|
-
- lib/sportdb/formats/ground/ground_reader.rb
|
168
|
-
- lib/sportdb/formats/league/league_outline_reader.rb
|
169
|
-
- lib/sportdb/formats/league/league_reader.rb
|
170
|
-
- lib/sportdb/formats/match/conf_parser.rb
|
171
|
-
- lib/sportdb/formats/match/match_parser.rb
|
172
106
|
- lib/sportdb/formats/package.rb
|
173
|
-
- lib/sportdb/formats/
|
174
|
-
- lib/sportdb/formats/search/structs.rb
|
175
|
-
- lib/sportdb/formats/search/world.rb
|
107
|
+
- lib/sportdb/formats/quick_match_linter.rb
|
176
108
|
- lib/sportdb/formats/team/club_index_history.rb
|
177
|
-
- lib/sportdb/formats/team/club_reader.rb
|
178
|
-
- lib/sportdb/formats/team/club_reader_history.rb
|
179
|
-
- lib/sportdb/formats/team/club_reader_props.rb
|
180
|
-
- lib/sportdb/formats/team/wiki_reader.rb
|
181
109
|
- lib/sportdb/formats/version.rb
|
182
110
|
homepage: https://github.com/sportdb/sport.db
|
183
111
|
licenses:
|
@@ -1,142 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
|
4
|
-
module SportDb
|
5
|
-
module Import
|
6
|
-
|
7
|
-
|
8
|
-
class CountryReader
|
9
|
-
|
10
|
-
|
11
|
-
def self.read( path ) ## use - rename to read_file or from_file etc. - why? why not?
|
12
|
-
txt = File.open( path, 'r:utf-8' ) { |f| f.read }
|
13
|
-
parse( txt )
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.parse( txt )
|
17
|
-
new( txt ).parse
|
18
|
-
end
|
19
|
-
|
20
|
-
|
21
|
-
def initialize( txt )
|
22
|
-
@txt = txt
|
23
|
-
end
|
24
|
-
|
25
|
-
def parse
|
26
|
-
countries = []
|
27
|
-
last_country = nil ## note/check/fix: use countries[-1] - why? why not?
|
28
|
-
|
29
|
-
OutlineReader.parse( @txt ).each do |node|
|
30
|
-
|
31
|
-
node_type = node[0]
|
32
|
-
|
33
|
-
if [:h1, :h2].include?( node_type )
|
34
|
-
## skip headings (and headings) for now too
|
35
|
-
elsif node_type == :p ## paragraph
|
36
|
-
lines = node[1]
|
37
|
-
lines.each do |line|
|
38
|
-
if line.start_with?( '|' )
|
39
|
-
## assume continuation with line of alternative names
|
40
|
-
## note: skip leading pipe
|
41
|
-
values = line[1..-1].split( '|' ) # team names - allow/use pipe(|)
|
42
|
-
## strip and squish (white)spaces
|
43
|
-
# e.g. East Germany (-1989) => East Germany (-1989)
|
44
|
-
values = values.map { |value| value.strip.gsub( /[ \t]+/, ' ' ) }
|
45
|
-
last_country.alt_names += values
|
46
|
-
elsif line =~ /^-[ ]*(\d{4})
|
47
|
-
[ ]+
|
48
|
-
(.+)$
|
49
|
-
/x ## check for historic lines e.g. -1989
|
50
|
-
year = $1.to_i
|
51
|
-
parts = $2.split( /=>|⇒/ )
|
52
|
-
values = parts[0].split( ',' )
|
53
|
-
values = values.map { |value| value.strip.gsub( /[ \t]+/, ' ' ) }
|
54
|
-
|
55
|
-
name = values[0]
|
56
|
-
code = values[1]
|
57
|
-
|
58
|
-
last_country = country = Country.new( name: "#{name} (-#{year})",
|
59
|
-
code: code )
|
60
|
-
## country.alt_names << name ## note: for now do NOT add name without year to alt_names - gets auto-add by index!!!
|
61
|
-
|
62
|
-
countries << country
|
63
|
-
## todo/fix: add reference to country today (in parts[1] !!!!)
|
64
|
-
else
|
65
|
-
## assume "regular" line
|
66
|
-
## check if starts with id (todo/check: use a more "strict"/better regex capture pattern!!!)
|
67
|
-
## note: allow country codes upto 4 (!!) e.g. Northern Cyprus
|
68
|
-
if line =~ /^([a-z]{2,4})
|
69
|
-
[ ]+
|
70
|
-
(.+)$/x
|
71
|
-
key = $1
|
72
|
-
values = $2.split( ',' )
|
73
|
-
## strip and squish (white)spaces
|
74
|
-
# e.g. East Germany (-1989) => East Germany (-1989)
|
75
|
-
values = values.map { |value| value.strip.gsub( /[ \t]+/, ' ' ) }
|
76
|
-
|
77
|
-
## note: remove "overlords" from geo-tree marked territories e.g. UK, US, etc. from name
|
78
|
-
## e.g. England › UK => England
|
79
|
-
## Puerto Rico › US => Puerto Rico
|
80
|
-
geos = split_geo( values[0] )
|
81
|
-
name = geos[0] ## note: ignore all other geos for now
|
82
|
-
|
83
|
-
## note: allow country codes up to 4 (!!) e.g. Northern Cyprus
|
84
|
-
code = if values[1] && values[1] =~ /^[A-Z]{3,4}$/ ## note: also check format
|
85
|
-
values[1]
|
86
|
-
else
|
87
|
-
if values[1]
|
88
|
-
puts "** !!! ERROR !!! wrong code format >#{values[1]}<; expected three (or four)-letter all up-case"
|
89
|
-
else
|
90
|
-
puts "** !!! ERROR !!! missing code for (canonical) country name"
|
91
|
-
end
|
92
|
-
exit 1
|
93
|
-
end
|
94
|
-
|
95
|
-
tags = if values[2] ## check if tags presents
|
96
|
-
split_tags( values[2] )
|
97
|
-
else
|
98
|
-
[]
|
99
|
-
end
|
100
|
-
|
101
|
-
last_country = country = Country.new( key: key,
|
102
|
-
name: name,
|
103
|
-
code: code,
|
104
|
-
tags: tags )
|
105
|
-
countries << country
|
106
|
-
else
|
107
|
-
puts "** !! ERROR - missing key for (canonical) country name"
|
108
|
-
exit 1
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end # each line
|
112
|
-
else
|
113
|
-
puts "** !! ERROR - unknown node type / (input) source line:"
|
114
|
-
pp node
|
115
|
-
exit 1
|
116
|
-
end
|
117
|
-
end # each node
|
118
|
-
|
119
|
-
countries
|
120
|
-
end # method parse
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
#######################################
|
125
|
-
## helpers
|
126
|
-
def split_tags( str )
|
127
|
-
tags = str.split( /[|<>‹›]/ ) ## allow pipe (|) and (<>‹›) as divider for now - add more? why? why not?
|
128
|
-
tags = tags.map { |tag| tag.strip }
|
129
|
-
tags
|
130
|
-
end
|
131
|
-
|
132
|
-
def split_geo( str ) ## todo/check: rename to parse_geo(s) - why? why not?
|
133
|
-
## split into geo tree
|
134
|
-
geos = str.split( /[<>‹›]/ ) ## note: allow > < or › ‹ for now
|
135
|
-
geos = geos.map { |geo| geo.strip } ## remove all whitespaces
|
136
|
-
geos
|
137
|
-
end
|
138
|
-
|
139
|
-
end # class CountryReader
|
140
|
-
|
141
|
-
end # module Import
|
142
|
-
end # module SportDb
|