sportdb-config 0.3.0 → 0.3.1
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/lib/sportdb/config/config.rb +39 -2
- data/lib/sportdb/config/version.rb +1 -1
- data/test/test_config.rb +26 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 352f71db80d07acc04fd4cb42c2bac55b1dd68c6
|
4
|
+
data.tar.gz: cc12464ae93f39bbc31b6f8afe0b01f7c090529d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d35cefa295d716caa25da70a39b73132d508075b2bfaee66d11f4f12a448005744e4d460df0718406e51a0e214acc371b8169c99ffd2b3b6dd98d1707e3c7d46
|
7
|
+
data.tar.gz: 7e1f607de7b27bfdc95897abe7eab6358115ff0b30d8029ce83eb937cdbe24c540e6bd78dc0e0977e5db80f4563653655d5553a9853ec86c0d34fadd5a5f5024
|
@@ -34,6 +34,38 @@ class Configuration
|
|
34
34
|
|
35
35
|
def clubs_dir() @clubs_dir ||= './clubs'; end
|
36
36
|
|
37
|
+
|
38
|
+
|
39
|
+
CLUBS_REGEX1 = %r{ (?:^|/) # beginning (^) or beginning of path (/)
|
40
|
+
(?<country>[a-z]{1,3})\.clubs\.txt$
|
41
|
+
}x
|
42
|
+
|
43
|
+
CLUBS_REGEX2 = %r{ (?:^|/) # beginning (^) or beginning of path (/)
|
44
|
+
(?<country>[a-z]{2,3})-[^/]+?
|
45
|
+
/clubs\.txt$
|
46
|
+
}x
|
47
|
+
|
48
|
+
CLUBS_REGEX = Regexp.union( CLUBS_REGEX1, CLUBS_REGEX2 )
|
49
|
+
|
50
|
+
|
51
|
+
def find_clubs_datafiles( path )
|
52
|
+
datafiles = [] ## note: [country, path] pairs for now
|
53
|
+
|
54
|
+
## check all txt files as candidates (MUST include country code for now)
|
55
|
+
candidates = Dir.glob( "#{path}/**/*.txt" )
|
56
|
+
pp candidates
|
57
|
+
candidates.each do |candidate|
|
58
|
+
m = CLUBS_REGEX.match( candidate )
|
59
|
+
if m
|
60
|
+
datafiles << [m[:country], candidate]
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
pp datafiles
|
65
|
+
datafiles
|
66
|
+
end
|
67
|
+
|
68
|
+
=begin
|
37
69
|
CLUBS_DATAFILES = { ## path by country to clubs.txt
|
38
70
|
de: 'europe/de-deutschland',
|
39
71
|
fr: 'europe/fr-france',
|
@@ -82,6 +114,8 @@ class Configuration
|
|
82
114
|
br: 'south-america/br-brazil',
|
83
115
|
jp: 'asia/jp-japan',
|
84
116
|
cn: 'asia/cn-china' }
|
117
|
+
=end
|
118
|
+
|
85
119
|
|
86
120
|
def read_teams
|
87
121
|
## unify team names; team (builtin/known/shared) name mappings
|
@@ -90,8 +124,11 @@ class Configuration
|
|
90
124
|
@errors = [] ## reset errors
|
91
125
|
|
92
126
|
## todo/fix: pass along / use country code too
|
93
|
-
|
94
|
-
|
127
|
+
datafiles = find_clubs_datafiles( clubs_dir )
|
128
|
+
datafiles.each do |datafile|
|
129
|
+
country = datafile[0] ## country code e.g. eng, at, de, etc.
|
130
|
+
path = datafile[1]
|
131
|
+
recs += TeamReader.read( path )
|
95
132
|
end
|
96
133
|
|
97
134
|
############################
|
data/test/test_config.rb
CHANGED
@@ -9,7 +9,32 @@ require 'helper'
|
|
9
9
|
|
10
10
|
class TestConfig < MiniTest::Test
|
11
11
|
|
12
|
-
|
12
|
+
|
13
|
+
def match1( txt ) SportDb::Import::Configuration::CLUBS_REGEX1.match( txt ); end
|
14
|
+
def match2( txt ) SportDb::Import::Configuration::CLUBS_REGEX2.match( txt ); end
|
15
|
+
|
16
|
+
def test_find_clubs
|
17
|
+
m = match1( 'de.clubs.txt' )
|
18
|
+
assert_equal 'de', m[:country]
|
19
|
+
|
20
|
+
m = match1( 'deutschland/de.clubs.txt' )
|
21
|
+
assert_equal 'de', m[:country]
|
22
|
+
|
23
|
+
m = match2( 'europe/de-deutschland/clubs.txt' )
|
24
|
+
assert_equal 'de', m[:country]
|
25
|
+
|
26
|
+
m = match2( 'de-deutschland/clubs.txt' )
|
27
|
+
assert_equal 'de', m[:country]
|
28
|
+
|
29
|
+
|
30
|
+
assert match1( 'clubs.txt' ) == nil
|
31
|
+
assert match2( 'clubs.txt' ) == nil
|
32
|
+
assert match1( 'deutschland/clubs.txt' ) == nil
|
33
|
+
assert match2( 'deutschland/clubs.txt' ) == nil
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
def test_clubs
|
13
38
|
SportDb::Import.config.clubs_dir = '../../../openfootball/clubs'
|
14
39
|
|
15
40
|
pp SportDb::Import.config.teams
|
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.3.
|
4
|
+
version: 0.3.1
|
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-07-
|
11
|
+
date: 2019-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|