sportdb-config 0.7.1 → 0.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b93799fb817b7e01251aa0e0466a139ae6a0154c
4
- data.tar.gz: 98b3f7cde0179d48242d65703947f76b65ab3a8b
3
+ metadata.gz: b3730a1e31df7d9bd0ebbdd4f1127cdf180d94fb
4
+ data.tar.gz: 236e45970f9e11585cb48a68547a98e641d6ad6d
5
5
  SHA512:
6
- metadata.gz: 970bb8795434f5689ebf44fc39bf102cb6aec35962db2ca23c2909a2ec342b91132a9982108eb8b34a408add5bae7b788d4101cf0c4351f79abfe6ce062af88a
7
- data.tar.gz: 213ab53677e5770539072ab14fd9aad721afb202d208ab287b4690db7d30564afb13e51059951e39ddbe391a712860480f1f86cbd7ecedc36cd84cfbc8630f9c
6
+ metadata.gz: aac070a5652cba90e1d0b1202241f4903e8ca76b8640037d64657ee6adcefa6a56618b97b2cf927cd8cc2eb1aa4ba734e1c8282476f29201afc261316f4bf8f5
7
+ data.tar.gz: 8735ac9a8e0cebafcc42a3d28bced5f539e1e85992382b156e6a7111adaa20088050c321b6d810b52ca8f434d810f5e31c5bb3483c26b4bba39cba6abb0d8886
@@ -3,28 +3,15 @@ Manifest.txt
3
3
  NOTES.md
4
4
  README.md
5
5
  Rakefile
6
- config/leagues/eng.txt
7
- config/leagues/fr.txt
8
- config/leagues/gr.txt
9
- config/leagues/sco.txt
10
- config/world/ar.txt
11
- config/world/at.txt
12
- config/world/be.txt
13
- config/world/de.txt
14
- config/world/eng.txt
15
6
  lib/sportdb/config.rb
16
7
  lib/sportdb/config/config.rb
17
- lib/sportdb/config/league.rb
18
- lib/sportdb/config/league_reader.rb
19
- lib/sportdb/config/league_utils.rb
20
8
  lib/sportdb/config/season_utils.rb
21
9
  lib/sportdb/config/version.rb
22
10
  lib/sportdb/config/wiki_index.rb
23
11
  test/helper.rb
24
12
  test/test_clubs.rb
25
- test/test_config.rb
26
13
  test/test_countries.rb
27
- test/test_league_reader.rb
28
- test/test_league_utils.rb
14
+ test/test_find_datafiles.rb
15
+ test/test_leagues.rb
29
16
  test/test_season_utils.rb
30
17
  test/test_wiki_index.rb
data/Rakefile CHANGED
@@ -22,13 +22,14 @@ Hoe.spec 'sportdb-config' do
22
22
  self.extra_deps = [
23
23
  ['sportdb-countries', '>= 0.2.0'],
24
24
  ['sportdb-clubs', '>= 0.2.0'],
25
+ ['sportdb-leagues', '>= 0.1.0'],
25
26
  ## dataset libs / gems
26
27
  ['fifa', '>= 1.0.0'], ## for (builtin/default) countries
27
- ['footballdb-clubs', '>= 0.2.0'], ## for (builtin/default) clubs
28
+ ['footballdb-clubs', '>= 1.0.0'], ## for (builtin/default) clubs
28
29
  ]
29
30
 
30
31
  self.spec_extras = {
31
- :required_ruby_version => '>= 2.2.2'
32
+ required_ruby_version: '>= 2.2.2'
32
33
  }
33
34
 
34
35
  end
@@ -3,6 +3,8 @@
3
3
  ### our own sportdb libs / gems
4
4
  require 'sportdb/countries'
5
5
  require 'sportdb/clubs'
6
+ require 'sportdb/leagues'
7
+
6
8
 
7
9
  ### "built-in" default dataset libs / gems
8
10
  require 'fifa' ## get a list of all fifa countries with (three letter) codes
@@ -14,19 +16,18 @@ require 'footballdb/clubs'
14
16
  require 'sportdb/config/version' # let version always go first
15
17
 
16
18
  require 'sportdb/config/season_utils'
17
- require 'sportdb/config/league_utils'
18
- require 'sportdb/config/league'
19
- require 'sportdb/config/league_reader'
20
19
  require 'sportdb/config/wiki_index'
21
20
  require 'sportdb/config/config'
22
21
 
23
22
 
24
23
 
25
24
  ## use global Import config - required for countries lookup / mapping (service)
26
- SportDb::Import::ClubReader.config = SportDb::Import.config
27
- SportDb::Import::ClubIndex.config = SportDb::Import.config
28
- SportDb::Import::WikiReader.config = SportDb::Import.config
25
+ SportDb::Import::ClubReader.config = SportDb::Import.config
26
+ SportDb::Import::ClubIndex.config = SportDb::Import.config
27
+ SportDb::Import::WikiReader.config = SportDb::Import.config
29
28
 
29
+ SportDb::Import::LeagueReader.config = SportDb::Import.config
30
+ SportDb::Import::LeagueIndex.config = SportDb::Import.config
30
31
 
31
32
 
32
33
 
@@ -3,7 +3,7 @@
3
3
  module SportDb
4
4
  module Import
5
5
 
6
- # add builder convenience helper to ClubIndex
6
+ # add builder convenience helper to ClubIndex - why? why not?
7
7
  class ClubIndex
8
8
 
9
9
  def self.build( path )
@@ -14,7 +14,7 @@ class ClubIndex
14
14
  end
15
15
  recs
16
16
 
17
- clubs = self.new
17
+ clubs = new
18
18
  clubs.add( recs )
19
19
 
20
20
  ## add wiki(pedia) anchored links
@@ -31,6 +31,23 @@ class ClubIndex
31
31
  end # class ClubIndex
32
32
 
33
33
 
34
+ class LeagueIndex
35
+
36
+ def self.build( path )
37
+ recs = []
38
+ datafiles = Configuration.find_datafiles_leagues( path )
39
+ datafiles.each do |datafile|
40
+ recs += LeagueReader.read( datafile )
41
+ end
42
+ recs
43
+
44
+ leagues = new
45
+ leagues.add( recs )
46
+ leagues
47
+ end
48
+ end # class LeagueIndex
49
+
50
+
34
51
  class Configuration
35
52
 
36
53
  ##
@@ -55,10 +72,19 @@ class Configuration
55
72
  @clubs
56
73
  end
57
74
 
75
+ def leagues
76
+ @leagues ||= build_league_index
77
+ @leagues
78
+ end
79
+
80
+
58
81
  ####
59
82
  # todo/fix: find a better way to configure club / team datasets
60
83
  attr_accessor :clubs_dir
61
- def clubs_dir() @clubs_dir; end ### note: return nil if NOT set on purpose for now - why? why not?
84
+ def clubs_dir() @clubs_dir; end ### note: return nil if NOT set on purpose for now - why? why not?
85
+
86
+ attr_accessor :leagues_dir
87
+ def leagues_dir() @leagues_dir; end
62
88
 
63
89
 
64
90
  CLUBS_REGEX = %r{ (?:^|/) # beginning (^) or beginning of path (/)
@@ -66,12 +92,16 @@ class Configuration
66
92
  clubs\.txt$
67
93
  }x
68
94
 
69
-
70
95
  CLUBS_WIKI_REGEX = %r{ (?:^|/) # beginning (^) or beginning of path (/)
71
96
  (?:[a-z]{1,3}\.)? # optional country code/key e.g. eng.clubs.wiki.txt
72
97
  clubs\.wiki\.txt$
73
98
  }x
74
99
 
100
+ LEAGUES_REGEX = %r{ (?:^|/) # beginning (^) or beginning of path (/)
101
+ (?:[a-z]{1,3}\.)? # optional country code/key e.g. eng.clubs.txt
102
+ leagues\.txt$
103
+ }x
104
+
75
105
 
76
106
  def self.find_datafiles( path, pattern )
77
107
  datafiles = [] ## note: [country, path] pairs for now
@@ -86,9 +116,11 @@ class Configuration
86
116
  pp datafiles
87
117
  datafiles
88
118
  end
119
+
89
120
  def self.find_datafiles_clubs( path ) find_datafiles( path, CLUBS_REGEX ); end
90
121
  def self.find_datafiles_clubs_wiki( path ) find_datafiles( path, CLUBS_WIKI_REGEX ); end
91
122
 
123
+ def self.find_datafiles_leagues( path ) find_datafiles( path, LEAGUES_REGEX ); end
92
124
 
93
125
 
94
126
  def build_club_index
@@ -115,23 +147,19 @@ class Configuration
115
147
  clubs
116
148
  end # method build_club_index
117
149
 
118
-
119
- def leagues
120
- read_leagues() if @leagues.nil?
121
- @leagues
150
+ def build_league_index
151
+ leagues = if leagues_dir ## check if clubs_dir is defined / set (otherwise it's nil)
152
+ LeagueIndex.build( leagues_dir )
153
+ else ## no leagues_dir set
154
+ puts "** !!! ERROR !! no config.leagues_dir set; sorry; CANNOT continue; please set"
155
+ exit 1
156
+ end
122
157
  end
123
158
 
124
- def read_leagues
125
- #####
126
- # add / read-in leagues config
127
- @leagues = LeagueConfig.new
128
159
 
129
- self ## return self for chaining
130
- end
131
160
  end # class Configuration
132
161
 
133
162
 
134
-
135
163
  ## lets you use
136
164
  ## SportDb::Import.configure do |config|
137
165
  ## config.hello = 'World'
@@ -7,8 +7,8 @@ module Boot ## note: use a different module than Config to avoid confusion
7
7
  ## maybe rename later gem itself to sportdb-boot - why? why not?
8
8
 
9
9
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
10
- MINOR = 7
11
- PATCH = 1
10
+ MINOR = 8
11
+ PATCH = 0
12
12
  VERSION = [MAJOR,MINOR,PATCH].join('.')
13
13
 
14
14
  def self.version
@@ -23,9 +23,9 @@ module Boot ## note: use a different module than Config to avoid confusion
23
23
  File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )
24
24
  end
25
25
 
26
- def self.data_dir ## rename to config_dir - why? why not?
27
- "#{root}/config"
28
- end
26
+ # def self.data_dir ## rename to config_dir - why? why not?
27
+ # "#{root}/config"
28
+ # end
29
29
 
30
30
 
31
31
  end # module Boot
@@ -10,4 +10,5 @@ require 'minitest/autorun'
10
10
  require 'sportdb/config'
11
11
 
12
12
 
13
- SportDb::Import.config.clubs_dir = '../../../openfootball/clubs'
13
+ SportDb::Import.config.clubs_dir = '../../../openfootball/clubs'
14
+ SportDb::Import.config.leagues_dir = '../../../openfootball/leagues'
@@ -2,16 +2,18 @@
2
2
 
3
3
  ###
4
4
  # to run use
5
- # ruby -I ./lib -I ./test test/test_config.rb
5
+ # ruby -I ./lib -I ./test test/test_find_datafiles.rb
6
6
 
7
7
 
8
8
  require 'helper'
9
9
 
10
- class TestConfig < MiniTest::Test
10
+ class TestFindDatafiles < MiniTest::Test
11
11
 
12
12
  def match_clubs( txt ) SportDb::Import::Configuration::CLUBS_REGEX.match( txt ); end
13
13
  def match_clubs_wiki( txt ) SportDb::Import::Configuration::CLUBS_WIKI_REGEX.match( txt ); end
14
14
 
15
+ def match_leagues( txt ) SportDb::Import::Configuration::LEAGUES_REGEX.match( txt ); end
16
+
15
17
  def test_find_clubs
16
18
  assert match_clubs( 'de.clubs.txt' )
17
19
  assert match_clubs( 'deutschland/de.clubs.txt' )
@@ -26,7 +28,6 @@ class TestConfig < MiniTest::Test
26
28
  assert !match_clubs( 'de-deutschland/clubs.wiki.txt' )
27
29
  assert !match_clubs( 'clubs.wiki.txt' )
28
30
  assert !match_clubs( 'deutschland/clubs.wiki.txt' )
29
-
30
31
  end
31
32
 
32
33
  def test_find_clubs_wiki
@@ -45,4 +46,12 @@ class TestConfig < MiniTest::Test
45
46
  assert match_clubs_wiki( 'deutschland/clubs.wiki.txt' )
46
47
  end
47
48
 
48
- end # class TestConfig
49
+ def test_find_leagues
50
+ assert match_leagues( 'eng.leagues.txt' )
51
+ assert match_leagues( 'england/eng.leagues.txt' )
52
+ assert match_leagues( 'europe/england/leagues.txt' )
53
+ assert match_leagues( 'england/leagues.txt' )
54
+ assert match_leagues( 'leagues.txt' )
55
+ end
56
+
57
+ end # class TestFindDatafiles
@@ -0,0 +1,24 @@
1
+ # encoding: utf-8
2
+
3
+ ###
4
+ # to run use
5
+ # ruby -I ./lib -I ./test test/test_leagues.rb
6
+
7
+
8
+ require 'helper'
9
+
10
+ class TestLeagues < MiniTest::Test
11
+
12
+ def test_match
13
+ pp SportDb::Import.config.leagues.errors
14
+
15
+ SportDb::Import.config.leagues.dump_duplicates
16
+
17
+ m = SportDb::Import.config.leagues.match( 'English Premier League' )
18
+ assert_equal 'English Premier League', m[0].name
19
+ assert_equal 'eng.1', m[0].key
20
+ assert_equal 'England', m[0].country.name
21
+ assert_equal 'eng', m[0].country.key
22
+ end
23
+
24
+ end # class TestLeagues
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.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: 2019-08-20 00:00:00.000000000 Z
11
+ date: 2019-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-countries
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: 0.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: sportdb-leagues
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: fifa
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -58,14 +72,14 @@ dependencies:
58
72
  requirements:
59
73
  - - ">="
60
74
  - !ruby/object:Gem::Version
61
- version: 0.2.0
75
+ version: 1.0.0
62
76
  type: :runtime
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
- version: 0.2.0
82
+ version: 1.0.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rdoc
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -103,44 +117,22 @@ extra_rdoc_files:
103
117
  - Manifest.txt
104
118
  - NOTES.md
105
119
  - README.md
106
- - config/leagues/eng.txt
107
- - config/leagues/fr.txt
108
- - config/leagues/gr.txt
109
- - config/leagues/sco.txt
110
- - config/world/ar.txt
111
- - config/world/at.txt
112
- - config/world/be.txt
113
- - config/world/de.txt
114
- - config/world/eng.txt
115
120
  files:
116
121
  - CHANGELOG.md
117
122
  - Manifest.txt
118
123
  - NOTES.md
119
124
  - README.md
120
125
  - Rakefile
121
- - config/leagues/eng.txt
122
- - config/leagues/fr.txt
123
- - config/leagues/gr.txt
124
- - config/leagues/sco.txt
125
- - config/world/ar.txt
126
- - config/world/at.txt
127
- - config/world/be.txt
128
- - config/world/de.txt
129
- - config/world/eng.txt
130
126
  - lib/sportdb/config.rb
131
127
  - lib/sportdb/config/config.rb
132
- - lib/sportdb/config/league.rb
133
- - lib/sportdb/config/league_reader.rb
134
- - lib/sportdb/config/league_utils.rb
135
128
  - lib/sportdb/config/season_utils.rb
136
129
  - lib/sportdb/config/version.rb
137
130
  - lib/sportdb/config/wiki_index.rb
138
131
  - test/helper.rb
139
132
  - test/test_clubs.rb
140
- - test/test_config.rb
141
133
  - test/test_countries.rb
142
- - test/test_league_reader.rb
143
- - test/test_league_utils.rb
134
+ - test/test_find_datafiles.rb
135
+ - test/test_leagues.rb
144
136
  - test/test_season_utils.rb
145
137
  - test/test_wiki_index.rb
146
138
  homepage: https://github.com/sportdb/sport.db
@@ -1,40 +0,0 @@
1
- ## all lowercase (no-space) key optional
2
- ## if not present auto-generate from name
3
-
4
- #############################
5
- ## todo / future: add number of clubs / teams ?? why? why not?
6
- ## add up/down - relegation?, champions league, europe league? etc.
7
- ## check how to handle groups with playoffs ? (e.g. see belgium)
8
- ##
9
- ## use 1/2 or 1+2 or => for relegation playoff - why? why not???
10
-
11
-
12
- 1 => premierleague, English Premier League
13
- 2 => championship, English Championship League
14
- 3 => league1, English League 1
15
- 4 => league2, English League 2
16
- 5 => conference, English Conference
17
-
18
- #########################################
19
- # until (including) 2003-04 season
20
-
21
- [2003-04] # or just use 2003-04: or similar - why? why not?
22
- # or use 2003/04 - 1992/93 - why? why not?
23
-
24
- 1 => premierleague, English Premier League
25
- 2 => division1, English Division 1
26
- 3 => division2, English Division 2
27
- 4 => division3, English Division 3
28
-
29
-
30
- #############################################
31
- # note: in season 1992/93 the premier league starts
32
- # until (including) 1991-92} season
33
-
34
- [1991-92]
35
- 1 => division1, English Division 1
36
- 2 => division2, English Division 2
37
- 3 => division3, English Division 3
38
- 3a => division3n, English Division 3 (North)
39
- 3b => division3s, English Division 3 (South)
40
- 4 => division4, English Division 4 ## check if real?
@@ -1,9 +0,0 @@
1
-
2
-
3
- 1 => ligue1, French Ligue 1
4
- 2 => ligue2, French Ligue 2
5
-
6
-
7
- [2001-02] ## until (including) 2001-02 season
8
- 1 => division1, ? ## use championat or something? check official name
9
- 2 => division2, ?
@@ -1,7 +0,0 @@
1
-
2
-
3
- 1 => superleague, Greek Superleague
4
-
5
-
6
- [2005-06] ## until (including) 2005-06 season
7
- 1 => alphaethniki, Greek Alpha Ethniki
@@ -1,19 +0,0 @@
1
-
2
- 1 => premiership, Scotish Premiership # starting w/ 2013-14 season
3
- 2 => championship, Scotish Championship
4
- 3 => league1, Scotish League One
5
- 4 => league2, Scotish League Two
6
-
7
-
8
- [2012-13] ## until (including) 2012-13 season
9
- 1 => premierleague, Scotish Premiership
10
- 2 => division1, Scotish 1st Division
11
- 3 => division2, Scotish League One
12
- 4 => division3, Scotish League Two
13
-
14
-
15
- [1997-98] ## until (including) season
16
- 1 => premierdivision, Scotish Premier Division
17
- 2 => division1, Scotish 1st Division
18
- 3 => division2, Scotish 2nd Division
19
- 4 => division3, Scotish 3rd Division
@@ -1,11 +0,0 @@
1
- ===========================
2
- = Argentina (ar)
3
-
4
- Buenos Aires
5
- Santa Fe | Provincia Santa Fe
6
- Córdoba | Provincia Córdoba
7
- Mendoza | Provincia Mendoza
8
- San Juan | Provincia San Juan
9
- Tucumán | Provincia Tucumán
10
- Entre Ríos | Provincia Entre Ríos
11
- Misiones | Provincia Misiones
@@ -1,19 +0,0 @@
1
- =================================
2
- = Österreich • Austria (at)
3
-
4
-
5
- Wien | Vienna [en]
6
- Burgenland
7
- Niederösterreich
8
- Oberösterreich
9
- Steiermark
10
- Kärnten
11
- Salzburg
12
- Tirol
13
- Vorarlberg
14
-
15
-
16
- == Niederösterreich ==
17
-
18
- Wr. Neustadt | Wiener Neustadt
19
- St. Pölten | Sankt Pölten
@@ -1,18 +0,0 @@
1
- ==================================
2
- = Belgium (be)
3
-
4
- Brussels
5
-
6
- Antwerpen › Vlaanderen | Antwerpen
7
- Limburg › Vlaanderen | Limburg
8
- Oost-Vlaanderen › Vlaanderen | Oost-Vlaanderen
9
- West-Vlaanderen › Vlaanderen | West-Vlaanderen
10
-
11
- Hainaut › Wallonie | Hainaut
12
- Liège › Wallonie | Liège
13
-
14
-
15
- == Hainaut › Wallonie ==
16
-
17
- Mouscron [fr] | Moeskroen [nl]
18
- Mons [fr] | Bergen [nl]
@@ -1,19 +0,0 @@
1
- ============================================
2
- = Germany • Deutschland (de)
3
-
4
- Bayern
5
- Nordrhein-Westfalen
6
- Saarland
7
- Niedersachsen
8
- Brandenburg
9
- Berlin
10
- Hamburg
11
- Bremen
12
- Baden-Württemberg
13
- Hessen
14
- Rheinland-Pfalz
15
- Schleswig-Holstein
16
- Mecklenburg-Vorpommern
17
- Sachsen
18
- Sachsen-Anhalt
19
- Thüringen
@@ -1,162 +0,0 @@
1
- ##
2
- # what name? use regions or maps or geos or zones or __?
3
-
4
- #
5
- # england
6
- # see https://en.wikipedia.org/wiki/Subdivisions_of_England
7
- # see https://www.bbc.co.uk/news/england/regions
8
-
9
- ##
10
- # todo: for sort order - allow different sort name
11
- # e.g. East Sussex => Sussex (East) or Sussex, East or something
12
- # use <> for marking what counts for sorting
13
- # e.g East <Sussex> => get auto-converted to Sussex, East - why? why not?
14
- #
15
- # more examples:
16
- # North ‹Yorkshire› => Yorkshire (North) or Yorkshire, North
17
- # Greater ‹London› => London, Greater
18
- # Greater ‹Manchaster› => Manchaster, Greater
19
-
20
-
21
- ##
22
- # note: uses all regions following the camra good beer guide (book)
23
- #
24
-
25
- ======================================
26
- == North West England ==
27
-
28
- # Cumbria
29
- # Lancashire
30
- # Liverpool
31
- # Manchester
32
-
33
- Cheshire
34
- Cumbria
35
- Lancashire
36
- Greater Manchester | Manchester, Greater
37
- Liverpool & Merseyside | Merseyside ## note: added Liverpool & - why? why not?
38
-
39
-
40
- ===================================
41
- == North East England
42
-
43
- # Tees
44
- # Tyne & Wear
45
-
46
- Durham
47
- Newcastle & Northumberland | Northumberland ## note: added Newcastle & - why? why not?
48
- Tyne and Wear
49
-
50
-
51
- =====================================
52
- == Yorkshire & Lincolnshire ==
53
-
54
- # Humberside
55
- # Leeds & West Yorkshire
56
- # Lincolnshire
57
- # Sheffield & South Yorkshire
58
- # York & North Yorkshire
59
-
60
- Lincolnshire
61
- West Yorkshire | Yorkshire, West | Yorkshire (West)
62
- South Yorkshire | Yorkshire, South | Yorkshire (South)
63
- North Yorkshire | Yorkshire, North | Yorkshire (North)
64
- East Yorkshire | Yorkshire, East | Yorkshire (East)
65
-
66
-
67
- ==================================
68
- == West Midlands
69
-
70
- # Birmingham & Black Country
71
- # Coventry & Warwickshire
72
- # Hereford & Worcester
73
- # Shropshire
74
- # Stoke & Staffordshire
75
-
76
- Herefordshire
77
- Shropshire
78
- Staffordshire
79
- Warwickshire
80
- Birmingham & West Midlands | West Midlands ## note: added Birmingham - why? why not?
81
- Worcestershire
82
-
83
-
84
- ==================================
85
- == East Midlands
86
-
87
- # Derby
88
- # Leicester
89
- # Northampton
90
- # Nottingham
91
-
92
- Derbyshire
93
- Leicestershire
94
- Northamptonshire
95
- Nottinghamshire
96
- Rutland
97
-
98
-
99
- ===================================
100
- == West & South West
101
-
102
- # Bristol
103
- # Cornwall
104
- # Devon
105
- # Gloucestershire
106
- # Somerset
107
- # Wiltshire
108
-
109
-
110
- Cornwall
111
- Devon
112
- Bristol & Gloucestershire | Gloucestershire
113
- Somerset
114
- Wiltshire
115
-
116
-
117
- =================================
118
- == East
119
-
120
- # Beds, Herts & Bucks
121
- # Cambridgeshire
122
- # Essex
123
- # Norfolk
124
- # Suffolk
125
-
126
- Bedfordshire
127
- Hertfordshire
128
- Buckinghamshire
129
- Cambridgeshire
130
- Essex
131
- Norfolk
132
- Suffolk
133
-
134
-
135
- ===============================
136
- == South
137
-
138
- # Berkshire
139
- # Dorset
140
- # Hampshire & Isle of Wight
141
- # Oxford
142
-
143
- Berkshire
144
- Dorset
145
- Hampshire
146
- Oxfordshire
147
-
148
-
149
-
150
- ===============================
151
- == London & South East
152
-
153
- # Kent
154
- # London
155
- # Surrey
156
- # Sussex
157
-
158
- Greater London | London, Greater
159
- Kent
160
- Surrey
161
- East Sussex | Sussex, East | Sussex (East)
162
- West Sussex | Sussex, West | Sussex (West)
@@ -1,118 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
- module Import
5
-
6
-
7
- class LeagueConfig ## use LeagueInfo or LeagueMap or LeagueHash or similar
8
-
9
- def initialize
10
-
11
- ## just use leagues without latest for latest - why? why not?
12
- @leagues_latest = {
13
- 'es' => { '1' => 'liga', # spanish liga 1
14
- '2' => 'liga2', # spanish liga 2
15
- },
16
- 'it' => { '1' => 'seriea', # italian serie a
17
- '2' => 'serieb', # italian serie b
18
- },
19
- 'de' => { '1' => 'bundesliga', # german bundesliga
20
- '2' => 'bundesliga2', # german 2. bundesliga
21
- },
22
- 'nl' => { '1' => 'eredivisie' }, # dutch eredivisie
23
- 'be' => { '1' => 'proleague' }, # belgian pro league
24
- 'pt' => { '1' => 'liga' }, # portugese Primeira Liga
25
- 'tr' => { '1' => 'superlig' }, # turkish Süper Lig
26
-
27
- # note: eng now read from txt
28
- # 'eng' => { '1' => 'premierleague', # english premier league
29
- # '2' => 'championship', # english championship league
30
- # '3' => 'league1', # english league 1
31
- # },
32
- }
33
-
34
- ## change history to past or changes/changelog something - why? why not?
35
- @leagues_history = {
36
-
37
- # note: eng now read from txt
38
- # 'eng' => {
39
- # ## until (including) 2003-04 season
40
- # '2003-04' => { '1' => 'premierleague', # english premier league
41
- # '2' => 'division1', # english division 1
42
- # },
43
- # ## until (including) 1991-92} season
44
- # '1991-92' => { '1' => 'division1', # english division 1
45
- # '2' => 'division2', # english division 2
46
- # }
47
- # }
48
- }
49
-
50
- pp @leagues_latest
51
- pp @leagues_history
52
-
53
- %w(eng sco fr gr).each do |country|
54
- hash = LeagueReader.read( "#{Boot.data_dir}/leagues/#{country}.txt" )
55
- pp hash
56
-
57
- hash.each do |season,league_hash|
58
- if season == '*' ## assume latest / default season
59
- @leagues_latest[ country ] = league_hash
60
- else
61
- @leagues_history[ country ] ||= {}
62
- @leagues_history[ country ][ season ] = league_hash
63
- end
64
- end
65
- end
66
-
67
- pp @leagues_latest
68
- pp @leagues_history
69
- end
70
-
71
-
72
-
73
- def basename( league, country:, season: )
74
- ## todo/check: rename league: to key: - why? why not?
75
-
76
- if country.include?( '-' ) ## assume package name e.g. eng-england etc.
77
- ## cut off country code from package name
78
- cc = country.split( '-' )[0] # use first part
79
- else
80
- cc = country
81
- end
82
-
83
- if season
84
- puts " checking season >#{season}<"
85
- ## check history if season is provided / supplied / known
86
- history = @leagues_history[ cc ]
87
- if history
88
- season_start_year = SeasonUtils.start_year( season ).to_i
89
- ##
90
- ## todo: sorty season keys - why? why not? -- assume reverse chronological order for now
91
- history.keys.reverse.each do |key|
92
- history_season_start_year = SeasonUtils.start_year( key ).to_i
93
- puts " #{season_start_year} <= #{history_season_start_year} - #{season_start_year <= history_season_start_year}"
94
- if season_start_year <= history_season_start_year
95
- result = history[ key ][ league ]
96
- if result
97
- return "#{league}-#{result}"
98
- else
99
- return nil
100
- end
101
- end
102
- end
103
- end
104
- end
105
-
106
- latest = @leagues_latest[ cc ]
107
- if latest
108
- result = latest[ league ]
109
- return "#{league}-#{result}" if result
110
- end
111
-
112
- nil
113
- end # method basename
114
- end # class LeagueConfig
115
-
116
-
117
- end ## module Import
118
- end ## module SportDb
@@ -1,65 +0,0 @@
1
- # encoding: utf-8
2
-
3
-
4
- module SportDb
5
- module Import
6
-
7
- class LeagueReader
8
-
9
- def self.read( path )
10
- txt = File.open( path, 'r:utf-8' ).read
11
- parse( txt )
12
- end
13
-
14
-
15
-
16
- SEASON_REGEX = /\[
17
- (?<season>
18
- \d{4}
19
- (-\d{2,4})?
20
- )
21
- \]/x
22
-
23
- def self.parse( txt )
24
- hash = {}
25
- season = '*' ## use '*' for default/latest season
26
-
27
- txt.each_line do |line|
28
- line = line.strip
29
-
30
- next if line.empty?
31
- next if line.start_with?( '#' ) ## skip comments too
32
-
33
- ## strip inline comments too
34
- line = line.sub( /#.*/, '' ).strip
35
-
36
- pp line
37
-
38
-
39
- if (m=line.match( SEASON_REGEX ))
40
- season = m[:season]
41
- else
42
- key_line, values_line = line.split( '=>' )
43
- values = values_line.split( ',' )
44
-
45
- ## remove leading and trailing spaces
46
- key_line = key_line.strip
47
- values = values.map { |value| value.strip }
48
- pp values
49
-
50
- league_key = key_line
51
- league_basename = values[0]
52
-
53
- hash[season] ||= {}
54
- hash[season][league_key] = league_basename
55
- end
56
- end
57
- hash
58
- end # method read
59
-
60
- end ## class LeagueReader
61
-
62
-
63
-
64
- end ## module Import
65
- end ## module SportDb
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
-
3
-
4
- module LeagueHelper
5
- def basename( league, country:, season: nil )
6
- ## e.g. eng-england, 2011-12, 1 returns 1-premierleague
7
- ##
8
- ## allow country code or (repo) package name
9
- ## e.g. eng-england or eng
10
- ## de-deutschland or de etc.
11
-
12
- leagues = SportDb::Import.config.leagues
13
-
14
- result = leagues.basename( league, country: country, season: season )
15
-
16
- ##
17
- # note: if no mapping / nothing found return league e.g. 1, 2, 3, 3a, 3b, cup(?), etc.
18
- result ? result : league
19
- end
20
- end
21
-
22
- module LeagueUtils
23
- extend LeagueHelper
24
- end
@@ -1,54 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_league_reader.rb
6
-
7
-
8
- require 'helper'
9
-
10
- class TestLeagueReader < MiniTest::Test
11
-
12
- def test_parse_eng
13
-
14
- hash = SportDb::Import::LeagueReader.parse( <<TXT )
15
- 1 => premierleague, English Premier League
16
- 2 => championship, English Championship League
17
- 3 => league1, English League 1
18
- 4 => league2, English League 2
19
- 5 => conference, English Conference
20
-
21
- #########################################
22
- # until (including) 2003-04 season
23
-
24
- [2003-04] # or just use 2003-04: or similar - why? why not?
25
- # or use 2003/04 - 1992/93 - why? why not?
26
-
27
- 1 => premierleague, English Premier League
28
- 2 => division1, English Division 1
29
- 3 => division2, English Division 2
30
- 4 => division3, English Division 3
31
-
32
-
33
- #############################################
34
- # note: in season 1992/93 the premier league starts
35
- # until (including) 1991-92} season
36
-
37
- [1991-92]
38
- 1 => division1, English Division 1
39
- 2 => division2, English Division 2
40
- 3 => division3, English Division 3
41
- 3a => division3n, English Division 3 (North)
42
- 3b => division3s, English Division 3 (South)
43
- 4 => division4, English Division 4 ## check if real?
44
- TXT
45
-
46
-
47
- assert_equal 'premierleague', hash['*']['1']
48
- assert_equal 'championship', hash['*']['2']
49
- assert_equal 'league1', hash['*']['3']
50
-
51
- assert_equal 'division1', hash['1991-92']['1']
52
- assert_equal 'division2', hash['1991-92']['2']
53
- end # method test_parse_eng
54
- end # class TestLeagueUtils
@@ -1,46 +0,0 @@
1
- # encoding: utf-8
2
-
3
- ###
4
- # to run use
5
- # ruby -I ./lib -I ./test test/test_league_utils.rb
6
-
7
-
8
- require 'helper'
9
-
10
- class TestLeagueUtils < MiniTest::Test
11
-
12
- def test_basename_eng
13
- assert_equal '1-premierleague', LeagueUtils.basename( '1', country: 'eng', season: '2011-12' )
14
- assert_equal '1-premierleague', LeagueUtils.basename( '1', country: 'eng' )
15
- assert_equal '1-premierleague', LeagueUtils.basename( '1', country: 'eng-england' ) ## allow country code or (repo) package name
16
- assert_equal '1-division1', LeagueUtils.basename( '1', country: 'eng', season: '1991-92' )
17
- assert_equal '3a', LeagueUtils.basename( '3a', country: 'eng', season: '2011-12' )
18
-
19
- assert_equal '2-championship', LeagueUtils.basename( '2', country: 'eng', season: '2011-12' )
20
- assert_equal '2-championship', LeagueUtils.basename( '2', country: 'eng' )
21
- assert_equal '2-championship', LeagueUtils.basename( '2', country: 'eng-england' ) ## allow country code or (repo) package name
22
- assert_equal '2-division1', LeagueUtils.basename( '2', country: 'eng', season: '2003-04' )
23
- assert_equal '2-division2', LeagueUtils.basename( '2', country: 'eng', season: '1991-92' )
24
- assert_equal '2-division2', LeagueUtils.basename( '2', country: 'eng', season: '1989-90' )
25
- end # method test_basename
26
-
27
- def test_basename_sco
28
- assert_equal '1-premiership', LeagueUtils.basename( '1', country: 'sco' )
29
- assert_equal '1-premierleague', LeagueUtils.basename( '1', country: 'sco', season: '2012-13' )
30
- assert_equal '1-premierdivision', LeagueUtils.basename( '1', country: 'sco', season: '1997-98' )
31
-
32
- assert_equal '2-championship', LeagueUtils.basename( '2', country: 'sco' )
33
- assert_equal '2-division1', LeagueUtils.basename( '2', country: 'sco', season: '2012-13' )
34
- end
35
-
36
- def test_basename_fr
37
- assert_equal '1-ligue1', LeagueUtils.basename( '1', country: 'fr' )
38
- assert_equal '1-division1', LeagueUtils.basename( '1', country: 'fr', season: '2001-02' )
39
- end
40
-
41
- def test_basename_gr
42
- assert_equal '1-superleague', LeagueUtils.basename( '1', country: 'gr' )
43
- assert_equal '1-alphaethniki', LeagueUtils.basename( '1', country: 'gr', season: '2005-06' )
44
- end
45
-
46
- end # class TestLeagueUtils