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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1ae1c9a151f0ae45288637a313a7e931add98d41
4
- data.tar.gz: 630ce245f08fb76a88d90366cc2b0c4ae1145fae
3
+ metadata.gz: 352f71db80d07acc04fd4cb42c2bac55b1dd68c6
4
+ data.tar.gz: cc12464ae93f39bbc31b6f8afe0b01f7c090529d
5
5
  SHA512:
6
- metadata.gz: f0c92d020a856963d9eb77b8d58dc52c1b59a0fcec4cedf9786ee016d667460527ce62a01114cc181a6bd721692f93fd4e659f8bc6c8ed8b3a8360153749ddd4
7
- data.tar.gz: cbb79330d79b539240c1298f504a2bc46729dbf967dd7c1b9e60226d1e09539068cdccc8af288ab127d94423c1c65173ed9a63c90a8d6317e6e4506639c47ad0
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
- CLUBS_DATAFILES.each do |country, path|
94
- recs += TeamReader.read( "#{clubs_dir}/#{path}/clubs.txt" )
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
  ############################
@@ -8,7 +8,7 @@ module Boot ## note: use a different module than Config to avoid confusion
8
8
 
9
9
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
10
10
  MINOR = 3
11
- PATCH = 0
11
+ PATCH = 1
12
12
  VERSION = [MAJOR,MINOR,PATCH].join('.')
13
13
 
14
14
  def self.version
data/test/test_config.rb CHANGED
@@ -9,7 +9,32 @@ require 'helper'
9
9
 
10
10
  class TestConfig < MiniTest::Test
11
11
 
12
- def test_teams
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.0
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-07 00:00:00.000000000 Z
11
+ date: 2019-07-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rdoc