sportdb-config 1.0.1 → 1.0.2
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/Manifest.txt +2 -0
- data/lib/sportdb/config/catalog.rb +75 -0
- data/lib/sportdb/config/version.rb +1 -1
- data/test/test_national_teams.rb +40 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 65fb2dad1f7a9da1ca402af272f9ea574219b586
|
4
|
+
data.tar.gz: 531f43fc38f1347fcb60203be85b7f084d203ae2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9aadac096effcee44c6a85ac1c47d0f9926872ee076003a6901f13c69995d4c6f61e0db98c2a3141bc1ddbf4e7ff18b26255cd9c12312e9285ffa6a4b3822d10
|
7
|
+
data.tar.gz: 821e17820804ec765e58bc3c4c061553e0803b1fb1dfb624821c02659cfa49ef95fda03515c85851605048aeb64e960f40eee2474889a5c7f0495483e66b9c92
|
data/Manifest.txt
CHANGED
@@ -4,6 +4,7 @@ NOTES.md
|
|
4
4
|
README.md
|
5
5
|
Rakefile
|
6
6
|
lib/sportdb/config.rb
|
7
|
+
lib/sportdb/config/catalog.rb
|
7
8
|
lib/sportdb/config/config.rb
|
8
9
|
lib/sportdb/config/version.rb
|
9
10
|
lib/sportdb/config/wiki_index.rb
|
@@ -11,4 +12,5 @@ test/helper.rb
|
|
11
12
|
test/test_clubs.rb
|
12
13
|
test/test_countries.rb
|
13
14
|
test/test_leagues.rb
|
15
|
+
test/test_national_teams.rb
|
14
16
|
test/test_wiki_index.rb
|
@@ -0,0 +1,75 @@
|
|
1
|
+
|
2
|
+
module SportDb
|
3
|
+
module Import
|
4
|
+
|
5
|
+
|
6
|
+
class Catalog
|
7
|
+
def config() Import.config; end
|
8
|
+
|
9
|
+
|
10
|
+
## todo/check: rename to country_mappings/index - why? why not?
|
11
|
+
## or countries_by_code or countries_by_key
|
12
|
+
def countries() @countries ||= build_country_index; end
|
13
|
+
def national_teams() @national_teams ||= build_national_team_index; end
|
14
|
+
def clubs() @clubs ||= build_club_index; end
|
15
|
+
def teams() @teams ||= build_team_index; end
|
16
|
+
def leagues() @leagues ||= build_league_index; end
|
17
|
+
|
18
|
+
|
19
|
+
def build_team_index() TeamIndex.new; end
|
20
|
+
|
21
|
+
def build_country_index ## todo/check: rename to setup_country_index or read_country_index - why? why not?
|
22
|
+
CountryIndex.new( Fifa.countries )
|
23
|
+
end
|
24
|
+
|
25
|
+
def build_national_team_index
|
26
|
+
## auto-build national teams from Fifa.countries for now
|
27
|
+
teams = []
|
28
|
+
Fifa.countries.each do |country|
|
29
|
+
team = NationalTeam.new( key: country.fifa.downcase, ## note: use fifa code
|
30
|
+
name: country.name,
|
31
|
+
code: country.fifa, ## note: use fifa code
|
32
|
+
alt_names: country.alt_names )
|
33
|
+
team.country = country
|
34
|
+
|
35
|
+
teams << team
|
36
|
+
end
|
37
|
+
|
38
|
+
NationalTeamIndex.new( teams )
|
39
|
+
end
|
40
|
+
|
41
|
+
def build_club_index
|
42
|
+
## unify team names; team (builtin/known/shared) name mappings
|
43
|
+
## cleanup team names - use local ("native") name with umlaut etc.
|
44
|
+
## todo/fix: add to teamreader
|
45
|
+
## check that name and alt_names for a club are all unique (not duplicates)
|
46
|
+
|
47
|
+
clubs = if config.clubs_dir ## check if clubs_dir is defined / set (otherwise it's nil)
|
48
|
+
ClubIndex.build( config.clubs_dir )
|
49
|
+
else ## no clubs_dir set - try using builtin from footballdb-clubs
|
50
|
+
FootballDb::Import::build_club_index
|
51
|
+
end
|
52
|
+
|
53
|
+
if clubs.errors?
|
54
|
+
puts ""
|
55
|
+
puts "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
|
56
|
+
puts " #{clubs.errors.size} errors:"
|
57
|
+
pp clubs.errors
|
58
|
+
## exit 1
|
59
|
+
end
|
60
|
+
|
61
|
+
clubs
|
62
|
+
end # method build_club_index
|
63
|
+
|
64
|
+
|
65
|
+
def build_league_index
|
66
|
+
leagues = if config.leagues_dir ## check if clubs_dir is defined / set (otherwise it's nil)
|
67
|
+
LeagueIndex.build( config.leagues_dir )
|
68
|
+
else ## no leagues_dir set - try using builtin from footballdb-leagues
|
69
|
+
FootballDb::Import.build_league_index
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end # class Catalog
|
73
|
+
|
74
|
+
end # module Import
|
75
|
+
end # module SportDb
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_national_teams.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestNationalTeams < MiniTest::Test
|
11
|
+
|
12
|
+
NATIONAL_TEAMS = SportDb::Import.catalog.national_teams
|
13
|
+
|
14
|
+
|
15
|
+
def test_find
|
16
|
+
t = NATIONAL_TEAMS.find( 'AUT' )
|
17
|
+
assert_equal 'Austria', t.name
|
18
|
+
assert_equal 'aut', t.key
|
19
|
+
assert_equal 'AUT', t.code
|
20
|
+
|
21
|
+
|
22
|
+
t = NATIONAL_TEAMS.find( 'England' )
|
23
|
+
assert_equal 'England', t.name
|
24
|
+
assert_equal 'eng', t.key
|
25
|
+
assert_equal 'ENG', t.code
|
26
|
+
|
27
|
+
## note: all dots (.) get always removed
|
28
|
+
t = NATIONAL_TEAMS.find( '...e.n.g.l.a.n.d...' )
|
29
|
+
assert_equal 'England', t.name
|
30
|
+
assert_equal 'eng', t.key
|
31
|
+
assert_equal 'ENG', t.code
|
32
|
+
|
33
|
+
## note: all spaces and dashes (-) get always removed
|
34
|
+
t = NATIONAL_TEAMS.find( '--- e n g l a n d ---' )
|
35
|
+
assert_equal 'England', t.name
|
36
|
+
assert_equal 'eng', t.key
|
37
|
+
assert_equal 'ENG', t.code
|
38
|
+
end
|
39
|
+
|
40
|
+
end # class TestNationalTeams
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- README.md
|
111
111
|
- Rakefile
|
112
112
|
- lib/sportdb/config.rb
|
113
|
+
- lib/sportdb/config/catalog.rb
|
113
114
|
- lib/sportdb/config/config.rb
|
114
115
|
- lib/sportdb/config/version.rb
|
115
116
|
- lib/sportdb/config/wiki_index.rb
|
@@ -117,6 +118,7 @@ files:
|
|
117
118
|
- test/test_clubs.rb
|
118
119
|
- test/test_countries.rb
|
119
120
|
- test/test_leagues.rb
|
121
|
+
- test/test_national_teams.rb
|
120
122
|
- test/test_wiki_index.rb
|
121
123
|
homepage: https://github.com/sportdb/sport.db
|
122
124
|
licenses:
|