sportdb-config 0.2.3 → 0.3.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/lib/sportdb/config/team_reader.rb +44 -2
- data/lib/sportdb/config/version.rb +2 -2
- data/test/test_team_reader.rb +52 -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: 1ae1c9a151f0ae45288637a313a7e931add98d41
|
4
|
+
data.tar.gz: 630ce245f08fb76a88d90366cc2b0c4ae1145fae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0c92d020a856963d9eb77b8d58dc52c1b59a0fcec4cedf9786ee016d667460527ce62a01114cc181a6bd721692f93fd4e659f8bc6c8ed8b3a8360153749ddd4
|
7
|
+
data.tar.gz: cbb79330d79b539240c1298f504a2bc46729dbf967dd7c1b9e60226d1e09539068cdccc8af288ab127d94423c1c65173ed9a63c90a8d6317e6e4506639c47ad0
|
@@ -15,9 +15,19 @@ class Team
|
|
15
15
|
## todo: use just names for alt_names - why? why not?
|
16
16
|
attr_accessor :name, :alt_names, :year, :ground, :city
|
17
17
|
|
18
|
+
## more attribs - todo/fix - also add "upstream" to struct & model!!!!!
|
19
|
+
attr_accessor :district, :geos, :year_end
|
20
|
+
|
21
|
+
def historic?() @year_end.nil? == false; end
|
22
|
+
alias_method :past?, :historic?
|
23
|
+
|
24
|
+
|
18
25
|
def initialize
|
19
26
|
@alt_names = []
|
20
27
|
end
|
28
|
+
|
29
|
+
|
30
|
+
|
21
31
|
end # class Team
|
22
32
|
|
23
33
|
|
@@ -56,6 +66,7 @@ def self.parse( txt )
|
|
56
66
|
|
57
67
|
## check for duplicates - simple check for now - fix/improve
|
58
68
|
## todo/fix: (auto)remove duplicates - why? why not?
|
69
|
+
## todo/fix: add canonical name too!! might get duplicated in alt names!!!
|
59
70
|
count = last_rec.alt_names.size
|
60
71
|
count_uniq = last_rec.alt_names.uniq.size
|
61
72
|
if count != count_uniq
|
@@ -91,8 +102,18 @@ def self.parse( txt )
|
|
91
102
|
if rec.name =~ /\(.+?\)/ ## note: use non-greedy (?) match
|
92
103
|
name = rec.name.gsub( /\(.+?\)/, '' ).strip
|
93
104
|
rec.alt_names << name
|
94
|
-
end
|
95
105
|
|
106
|
+
if rec.name =~ /\(([0-9]{4})-\)/ ## e.g. (2014-)
|
107
|
+
rec.year = $1.to_i
|
108
|
+
elsif rec.name =~ /\(-([0-9]{4})\)/ ## e.g. (-2014)
|
109
|
+
rec.year_end = $1.to_i
|
110
|
+
elsif rec.name =~ /\(([0-9]{4})-([0-9]{4})\)/ ## e.g. (2011-2014)
|
111
|
+
rec.year = $1.to_i
|
112
|
+
rec.year_end = $2.to_i
|
113
|
+
else
|
114
|
+
## todo/check: warn about unknown year format
|
115
|
+
end
|
116
|
+
end
|
96
117
|
|
97
118
|
## todo/check - check for unknown format values
|
98
119
|
## e.g. too many values, duplicate years, etc.
|
@@ -103,13 +124,34 @@ def self.parse( txt )
|
|
103
124
|
# e.g. León › Guanajuato => León › Guanajuato
|
104
125
|
value = value.strip.gsub( /[ \t]+/, ' ' )
|
105
126
|
if value =~/^\d{4}$/ # e.g 1904
|
127
|
+
## todo/check: issue warning if year is already set!!!!!!!
|
128
|
+
if rec.year
|
129
|
+
puts "!!! error - year already set to #{rec.year} - CANNOT overwrite with #{value}:"
|
130
|
+
pp rec
|
131
|
+
exit 1
|
132
|
+
end
|
106
133
|
rec.year = value.to_i
|
107
134
|
elsif value.start_with?( '@' ) # e.g. @ Anfield
|
108
135
|
## cut-off leading @ and spaces
|
109
136
|
rec.ground = value[1..-1].strip
|
110
137
|
else
|
111
138
|
## assume city / geo tree
|
112
|
-
|
139
|
+
## split into geo tree
|
140
|
+
geos = value.split( /[<>‹›]/ ) ## note: allow > < or › ‹
|
141
|
+
geos = geos.map { |geo| geo.strip } ## remove all whitespaces
|
142
|
+
|
143
|
+
city = geos[0]
|
144
|
+
## check for "embedded" district e.g. London (Fulham) or Hamburg (St. Pauli) etc.
|
145
|
+
if city =~ /\((.+?)\)/ ## note: use non-greedy (?) match
|
146
|
+
rec.district = $1.strip
|
147
|
+
city = city.gsub( /\(.+?\)/, '' ).strip
|
148
|
+
end
|
149
|
+
rec.city = city
|
150
|
+
|
151
|
+
if geos.size > 1
|
152
|
+
## cut-off city and keep the rest (of geo tree)
|
153
|
+
rec.geos = geos[1..-1]
|
154
|
+
end
|
113
155
|
end
|
114
156
|
end
|
115
157
|
|
@@ -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 =
|
11
|
-
PATCH =
|
10
|
+
MINOR = 3
|
11
|
+
PATCH = 0
|
12
12
|
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
13
13
|
|
14
14
|
def self.version
|
data/test/test_team_reader.rb
CHANGED
@@ -50,7 +50,58 @@ TXT
|
|
50
50
|
assert_equal 5, recs.size
|
51
51
|
assert_equal 'Atlanta United FC', recs[0].name
|
52
52
|
assert_equal 2017, recs[0].year
|
53
|
-
assert_equal 'Atlanta
|
53
|
+
assert_equal 'Atlanta', recs[0].city
|
54
|
+
assert_equal ['Georgia'], recs[0].geos
|
54
55
|
end
|
55
56
|
|
57
|
+
|
58
|
+
def test_parse_years
|
59
|
+
recs = SportDb::Import::TeamReader.parse( <<TXT )
|
60
|
+
FC Dallas (1996-), Frisco › Texas
|
61
|
+
Miami Fusion (1998-2001), Fort Lauderdale › Florida
|
62
|
+
CD Chivas USA (-2014), Carson › California
|
63
|
+
TXT
|
64
|
+
|
65
|
+
pp recs
|
66
|
+
|
67
|
+
assert_equal 3, recs.size
|
68
|
+
assert_equal 1996, recs[0].year
|
69
|
+
assert_equal false, recs[0].historic?
|
70
|
+
assert_equal false, recs[0].past?
|
71
|
+
|
72
|
+
assert_equal 1998, recs[1].year
|
73
|
+
assert_equal 2001, recs[1].year_end
|
74
|
+
assert_equal true, recs[1].historic?
|
75
|
+
assert_equal true, recs[1].past?
|
76
|
+
|
77
|
+
assert_equal 2014, recs[2].year_end
|
78
|
+
assert_equal true, recs[2].historic?
|
79
|
+
assert_equal true, recs[2].past?
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_parse_geos
|
83
|
+
recs = SportDb::Import::TeamReader.parse( <<TXT )
|
84
|
+
#
|
85
|
+
Fulham FC, 1879, @ Craven Cottage, London (Fulham) › Greater London
|
86
|
+
| Fulham | FC Fulham
|
87
|
+
Charlton Athletic FC, @ The Valley, London (Charlton) › Greater London
|
88
|
+
| Charlton | Charlton Athletic
|
89
|
+
|
90
|
+
St. Pauli, Hamburg (St. Pauli)
|
91
|
+
TXT
|
92
|
+
|
93
|
+
pp recs
|
94
|
+
|
95
|
+
assert_equal 3, recs.size
|
96
|
+
assert_equal 'London', recs[0].city
|
97
|
+
assert_equal 'Fulham', recs[0].district
|
98
|
+
assert_equal ['Greater London'], recs[0].geos
|
99
|
+
|
100
|
+
assert_equal 'London', recs[1].city
|
101
|
+
assert_equal 'Charlton', recs[1].district
|
102
|
+
assert_equal ['Greater London'], recs[1].geos
|
103
|
+
|
104
|
+
assert_equal 'Hamburg', recs[2].city
|
105
|
+
assert_equal 'St. Pauli', recs[2].district
|
106
|
+
end
|
56
107
|
end # class TestTeamReader
|
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.
|
4
|
+
version: 0.3.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-
|
11
|
+
date: 2019-07-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rdoc
|