sportdb-structs 0.1.3 → 0.2.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/CHANGELOG.md +2 -0
- data/Manifest.txt +1 -6
- data/README.md +3 -3
- data/Rakefile +1 -1
- data/lib/sportdb/structs/config.rb +7 -7
- data/lib/sportdb/structs/match_parser_csv.rb +1 -1
- data/lib/sportdb/structs/structs/country.rb +28 -1
- data/lib/sportdb/structs/structs/ground.rb +78 -0
- data/lib/sportdb/structs/structs/group.rb +11 -3
- data/lib/sportdb/structs/structs/league.rb +2 -5
- data/lib/sportdb/structs/structs/match.rb +29 -28
- data/lib/sportdb/structs/structs/round.rb +14 -1
- data/lib/sportdb/structs/structs/team.rb +48 -47
- data/lib/sportdb/structs/version.rb +4 -4
- data/lib/sportdb/structs.rb +39 -0
- metadata +7 -12
- data/test/helper.rb +0 -13
- data/test/test_clubs.rb +0 -38
- data/test/test_csv_reader.rb +0 -30
- data/test/test_match.rb +0 -30
- data/test/test_match_status_parser.rb +0 -57
- data/test/test_name_helper.rb +0 -65
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '009da80615ac77d643529d2feee7692ca31ce2c07c5f1dd45cf2667558af4b90'
|
4
|
+
data.tar.gz: 7368f410cfc3b4fa0af288c20399c1244841518cf5598ff443dcf17aaa881501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 56acdb1dc22c5b70f51c398e1ae912ff6bcbf50f021391efa5eba75d3ddeb4c1d069255fd715a891f6c4451f25f4c0212eb8769bd129755ede88ca322cd4e4e6
|
7
|
+
data.tar.gz: 35dcad60e6c784859d5c7218e4771ec5979cb4a07b1e07ba6f598e64fc968c1cfd75ee5e48f2c22996fa570a37292051b8f4f4e195ea2b9527ecfceef4753b6c
|
data/CHANGELOG.md
CHANGED
data/Manifest.txt
CHANGED
@@ -10,6 +10,7 @@ lib/sportdb/structs/match_status_parser.rb
|
|
10
10
|
lib/sportdb/structs/name_helper.rb
|
11
11
|
lib/sportdb/structs/structs/country.rb
|
12
12
|
lib/sportdb/structs/structs/goal.rb
|
13
|
+
lib/sportdb/structs/structs/ground.rb
|
13
14
|
lib/sportdb/structs/structs/group.rb
|
14
15
|
lib/sportdb/structs/structs/league.rb
|
15
16
|
lib/sportdb/structs/structs/match.rb
|
@@ -19,9 +20,3 @@ lib/sportdb/structs/structs/standings.rb
|
|
19
20
|
lib/sportdb/structs/structs/team.rb
|
20
21
|
lib/sportdb/structs/structs/team_usage.rb
|
21
22
|
lib/sportdb/structs/version.rb
|
22
|
-
test/helper.rb
|
23
|
-
test/test_clubs.rb
|
24
|
-
test/test_csv_reader.rb
|
25
|
-
test/test_match.rb
|
26
|
-
test/test_match_status_parser.rb
|
27
|
-
test/test_name_helper.rb
|
data/README.md
CHANGED
@@ -22,8 +22,8 @@ The `sportdb-structs` scripts are dedicated to the public domain.
|
|
22
22
|
Use it as you please with no restrictions whatsoever.
|
23
23
|
|
24
24
|
|
25
|
+
|
25
26
|
## Questions? Comments?
|
26
27
|
|
27
|
-
|
28
|
-
[
|
29
|
-
Thanks!
|
28
|
+
Yes, you can. More than welcome.
|
29
|
+
See [Help & Support »](https://github.com/openfootball/help)
|
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ Hoe.spec 'sportdb-structs' do
|
|
11
11
|
self.urls = { home: 'https://github.com/sportdb/sport.db' }
|
12
12
|
|
13
13
|
self.author = 'Gerald Bauer'
|
14
|
-
self.email = '
|
14
|
+
self.email = 'gerald.bauer@gmail.com'
|
15
15
|
|
16
16
|
# switch extension to .markdown for gihub formatting
|
17
17
|
self.readme_file = 'README.md'
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module SportDb
|
2
|
-
|
2
|
+
module Import
|
3
3
|
|
4
4
|
class Configuration
|
5
5
|
##
|
6
6
|
## todo: allow configure of countries_dir like clubs_dir
|
7
7
|
## "fallback" and use a default built-in world/countries.txt
|
8
8
|
|
9
|
-
|
9
|
+
## note: catalog defined/added in sports-catalogs gem!!!
|
10
|
+
## attr_accessor :catalog
|
10
11
|
|
11
12
|
attr_reader :lang
|
12
13
|
def lang=(value)
|
@@ -15,8 +16,10 @@ class Configuration
|
|
15
16
|
ScoreFormats.lang = value
|
16
17
|
SportDb.lang.lang = value
|
17
18
|
|
18
|
-
## todo/fix: change SportDb.lang to SportDb.parser.lang
|
19
|
-
##
|
19
|
+
## todo/fix: change SportDb.lang to SportDb.parser.lang
|
20
|
+
## or lang_parser or utils or someting !!!!
|
21
|
+
## use Sport.lang only as a read-only shortcut
|
22
|
+
# a la catalog for config.lang!!!!
|
20
23
|
end
|
21
24
|
|
22
25
|
end # class Configuration
|
@@ -26,13 +29,10 @@ end # class Configuration
|
|
26
29
|
## SportDb::Import.configure do |config|
|
27
30
|
## config.lang = 'it'
|
28
31
|
## end
|
29
|
-
|
30
32
|
def self.configure() yield( config ); end
|
31
33
|
|
32
34
|
def self.config() @config ||= Configuration.new; end
|
33
35
|
|
34
|
-
## e.g. use config.catalog -- keep Import.catalog as a shortcut (for "read-only" access)
|
35
|
-
def self.catalog() config.catalog; end
|
36
36
|
|
37
37
|
end # module Import
|
38
38
|
end # module SportDb
|
@@ -116,7 +116,7 @@ module SportDb
|
|
116
116
|
|
117
117
|
header_league = find_header( headers, ['League'] )
|
118
118
|
headers_mapping[:league] = header_league if header_league
|
119
|
-
|
119
|
+
else
|
120
120
|
## else try footballdata.uk and others
|
121
121
|
headers_mapping[:team1] = find_header( headers, ['HomeTeam', 'HT', 'Home'] )
|
122
122
|
headers_mapping[:team2] = find_header( headers, ['AwayTeam', 'AT', 'Away'] )
|
@@ -4,6 +4,25 @@ module Sports
|
|
4
4
|
# note: check that shape/structure/fields/attributes match
|
5
5
|
# the ActiveRecord model !!!!
|
6
6
|
|
7
|
+
## add city here
|
8
|
+
## use module World - why? why not?
|
9
|
+
|
10
|
+
class City
|
11
|
+
attr_reader :key, :name, :country
|
12
|
+
attr_accessor :alt_names
|
13
|
+
|
14
|
+
def initialize( key: nil,
|
15
|
+
name:, country: )
|
16
|
+
## note: auto-generate key "on-the-fly" if missing for now - why? why not?
|
17
|
+
## note: quick hack - auto-generate key, that is, remove all non-ascii chars and downcase
|
18
|
+
@key = key || unaccent(name).downcase.gsub( /[^a-z]/, '' ) + "_" + country.key
|
19
|
+
@name = name
|
20
|
+
@country = country
|
21
|
+
@alt_names = []
|
22
|
+
end
|
23
|
+
end # class City
|
24
|
+
|
25
|
+
|
7
26
|
class Country
|
8
27
|
|
9
28
|
## note: is read-only/immutable for now - why? why not?
|
@@ -14,7 +33,15 @@ class Country
|
|
14
33
|
def initialize( key: nil, name:, code:, tags: [] )
|
15
34
|
## note: auto-generate key "on-the-fly" if missing for now - why? why not?
|
16
35
|
## note: quick hack - auto-generate key, that is, remove all non-ascii chars and downcase
|
17
|
-
@key =
|
36
|
+
@key = begin
|
37
|
+
if key
|
38
|
+
key
|
39
|
+
elsif code
|
40
|
+
code.downcase
|
41
|
+
else
|
42
|
+
unaccent( name ).downcase.gsub( /[^a-z]/, '' )
|
43
|
+
end
|
44
|
+
end
|
18
45
|
@name, @code = name, code
|
19
46
|
@alt_names = []
|
20
47
|
@tags = tags
|
@@ -0,0 +1,78 @@
|
|
1
|
+
##
|
2
|
+
# based on teams/clubs
|
3
|
+
#
|
4
|
+
|
5
|
+
|
6
|
+
module Sports
|
7
|
+
|
8
|
+
|
9
|
+
class Ground
|
10
|
+
## todo: use just names for alt_names - why? why not?
|
11
|
+
attr_accessor :key, :name, :alt_names,
|
12
|
+
:year, :year_end, ## todo/fix: change year to start_year and end_year/year_end to end_year (like in season)!!!
|
13
|
+
:country,
|
14
|
+
:city, :district,
|
15
|
+
:geos,
|
16
|
+
:address
|
17
|
+
|
18
|
+
def names
|
19
|
+
## todo/check: add alt_names_auto too? - why? why not?
|
20
|
+
[@name] + @alt_names
|
21
|
+
end ## all names
|
22
|
+
|
23
|
+
def key
|
24
|
+
## note: auto-generate key "on-the-fly" if missing for now - why? why not?
|
25
|
+
## note: quick hack - auto-generate key, that is, remove all non-ascii chars and downcase
|
26
|
+
## fix update - allow numbers (0-9)
|
27
|
+
## add dash(-) plus parens () too!! for (-1999) or (1999-2011) or such
|
28
|
+
## add umlauts too for now - plus add more later!!!
|
29
|
+
##
|
30
|
+
## fix- add more (all) diacritics!!!
|
31
|
+
## GÍ Gøta (1926-2008)
|
32
|
+
## FC Suðuroy
|
33
|
+
## fix - remove dash(-) if not followed or preceded by year (four digits)!!!
|
34
|
+
##
|
35
|
+
## use new (autogen)key rule
|
36
|
+
## - 1st unaccent, 2nd downcase, 3rd remove space et al
|
37
|
+
## use keygen or autokey function or such - why? why not?
|
38
|
+
|
39
|
+
## note: ALWAYS auto-add city to key to make unique!!!!!
|
40
|
+
## e.g. Red Bull Arena, Allianz Arena etc.
|
41
|
+
|
42
|
+
@key ||= begin
|
43
|
+
fst = unaccent( @name ).downcase.gsub( /[^a-z0-9()-]/, '' )
|
44
|
+
snd = unaccent( city ).downcase.gsub( /[^a-z0-9]/, '' )
|
45
|
+
trd = country.key
|
46
|
+
## use / as separator (or @ or ??) - why? why not?
|
47
|
+
fst + '_' + snd + '_' + trd
|
48
|
+
end
|
49
|
+
@key
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
## todo/check
|
54
|
+
## check event_ifno - for start_date, end_date ??
|
55
|
+
## use same naming convention here too (start_year/end_year)
|
56
|
+
def historic?() @year_end ? true : false; end
|
57
|
+
alias_method :past?, :historic?
|
58
|
+
|
59
|
+
|
60
|
+
def initialize( **kwargs )
|
61
|
+
@alt_names = []
|
62
|
+
|
63
|
+
update( **kwargs ) unless kwargs.empty?
|
64
|
+
end
|
65
|
+
|
66
|
+
def update( **kwargs )
|
67
|
+
@key = kwargs[:key] if kwargs.has_key?( :key )
|
68
|
+
@name = kwargs[:name] if kwargs.has_key?( :name )
|
69
|
+
@alt_names = kwargs[:alt_names] if kwargs.has_key?( :alt_names )
|
70
|
+
|
71
|
+
@city = kwargs[:city] if kwargs.has_key?( :city )
|
72
|
+
## todo/fix: use city struct - why? why not?
|
73
|
+
## todo/fix: add country too or report unused keywords / attributes - why? why not?
|
74
|
+
|
75
|
+
self ## note - MUST return self for chaining
|
76
|
+
end
|
77
|
+
end # class Ground
|
78
|
+
end # module Sports
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module Sports
|
2
2
|
|
3
|
-
|
3
|
+
class Group
|
4
4
|
attr_reader :key, :name, :teams
|
5
5
|
|
6
6
|
def initialize( key: nil,
|
@@ -10,7 +10,15 @@ module Sports
|
|
10
10
|
@name = name
|
11
11
|
@teams = teams
|
12
12
|
end
|
13
|
-
end # class Group
|
14
13
|
|
14
|
+
def pretty_print( printer )
|
15
|
+
## todo/check - how to display/format key - use () or not - why? why not?
|
16
|
+
buf = String.new
|
17
|
+
buf << "<Group: #{@key ? @key : '?'} - #{@name} "
|
18
|
+
buf << @teams.pretty_print_inspect
|
19
|
+
buf << ">"
|
20
|
+
|
21
|
+
printer.text( buf )
|
22
|
+
end
|
23
|
+
end # class Group
|
15
24
|
end # module Sports
|
16
|
-
|
@@ -6,16 +6,13 @@ class League
|
|
6
6
|
attr_reader :key, :name, :country, :intl
|
7
7
|
attr_accessor :alt_names
|
8
8
|
|
9
|
-
## special import only attribs
|
10
|
-
attr_accessor :alt_names_auto ## auto-generated alt names
|
11
9
|
|
12
|
-
def initialize( key:, name:, alt_names: [],
|
10
|
+
def initialize( key:, name:, alt_names: [],
|
13
11
|
country: nil, intl: false, clubs: true )
|
14
12
|
@key = key
|
15
13
|
@name = name
|
16
14
|
@alt_names = alt_names
|
17
|
-
|
18
|
-
|
15
|
+
|
19
16
|
@country = country
|
20
17
|
@intl = intl
|
21
18
|
@clubs = clubs
|
@@ -21,8 +21,8 @@ class Match
|
|
21
21
|
:conf1, :conf2, ## special case for mls e.g. conference1, conference2 (e.g. west, east, central)
|
22
22
|
:country1, :country2, ## special case for champions league etc. - uses FIFA country code
|
23
23
|
:comments,
|
24
|
-
:league ## (optinal) added as text for now (use struct?)
|
25
|
-
|
24
|
+
:league, ## (optinal) added as text for now (use struct?)
|
25
|
+
:ground ## (optional) add as text line for now (incl. city, timezone etc.)
|
26
26
|
|
27
27
|
attr_accessor :goals ## todo/fix: make goals like all other attribs!!
|
28
28
|
|
@@ -39,28 +39,29 @@ class Match
|
|
39
39
|
|
40
40
|
def update( **kwargs )
|
41
41
|
## note: check with has_key? because value might be nil!!!
|
42
|
-
@date = kwargs[:date] if kwargs.has_key? :date
|
43
|
-
@time = kwargs[:time] if kwargs.has_key? :time
|
42
|
+
@date = kwargs[:date] if kwargs.has_key?( :date )
|
43
|
+
@time = kwargs[:time] if kwargs.has_key?( :time )
|
44
44
|
|
45
45
|
## todo/fix: use team1_name, team2_name or similar - for compat with db activerecord version? why? why not?
|
46
|
-
@team1 = kwargs[:team1] if kwargs.has_key? :team1
|
47
|
-
@team2 = kwargs[:team2] if kwargs.has_key? :team2
|
46
|
+
@team1 = kwargs[:team1] if kwargs.has_key?( :team1 )
|
47
|
+
@team2 = kwargs[:team2] if kwargs.has_key?( :team2 )
|
48
48
|
|
49
|
-
@conf1 = kwargs[:conf1] if kwargs.has_key? :conf1
|
50
|
-
@conf2 = kwargs[:conf2] if kwargs.has_key? :conf2
|
51
|
-
@country1 = kwargs[:country1] if kwargs.has_key? :country1
|
52
|
-
@country2 = kwargs[:country2] if kwargs.has_key? :country2
|
49
|
+
@conf1 = kwargs[:conf1] if kwargs.has_key?( :conf1 )
|
50
|
+
@conf2 = kwargs[:conf2] if kwargs.has_key?( :conf2 )
|
51
|
+
@country1 = kwargs[:country1] if kwargs.has_key?( :country1 )
|
52
|
+
@country2 = kwargs[:country2] if kwargs.has_key?( :country2 )
|
53
53
|
|
54
54
|
## note: round is a string!!! e.g. '1', '2' for matchday or 'Final', 'Semi-final', etc.
|
55
55
|
## todo: use to_s - why? why not?
|
56
|
-
@round = kwargs[:round] if kwargs.has_key? :round
|
57
|
-
@stage = kwargs[:stage] if kwargs.has_key? :stage
|
58
|
-
@leg = kwargs[:leg] if kwargs.has_key? :leg
|
59
|
-
@group = kwargs[:group] if kwargs.has_key? :group
|
60
|
-
@status = kwargs[:status] if kwargs.has_key? :status
|
61
|
-
@comments = kwargs[:comments] if kwargs.has_key? :comments
|
56
|
+
@round = kwargs[:round] if kwargs.has_key?( :round )
|
57
|
+
@stage = kwargs[:stage] if kwargs.has_key?( :stage )
|
58
|
+
@leg = kwargs[:leg] if kwargs.has_key?( :leg )
|
59
|
+
@group = kwargs[:group] if kwargs.has_key?( :group )
|
60
|
+
@status = kwargs[:status] if kwargs.has_key?( :status )
|
61
|
+
@comments = kwargs[:comments] if kwargs.has_key?( :comments )
|
62
62
|
|
63
|
-
@league = kwargs[:league] if kwargs.has_key? :league
|
63
|
+
@league = kwargs[:league] if kwargs.has_key?( :league )
|
64
|
+
@ground = kwargs[:ground] if kwargs.has_key?( :ground )
|
64
65
|
|
65
66
|
|
66
67
|
if kwargs.has_key?( :score ) ## check all-in-one score struct for convenience!!!
|
@@ -91,17 +92,17 @@ class Match
|
|
91
92
|
## @score2agg = score.score2agg
|
92
93
|
end
|
93
94
|
else
|
94
|
-
@score1 = kwargs[:score1] if kwargs.has_key? :score1
|
95
|
-
@score1i = kwargs[:score1i] if kwargs.has_key? :score1i
|
96
|
-
@score1et = kwargs[:score1et] if kwargs.has_key? :score1et
|
97
|
-
@score1p = kwargs[:score1p] if kwargs.has_key? :score1p
|
98
|
-
@score1agg = kwargs[:score1agg] if kwargs.has_key? :score1agg
|
99
|
-
|
100
|
-
@score2 = kwargs[:score2] if kwargs.has_key? :score2
|
101
|
-
@score2i = kwargs[:score2i] if kwargs.has_key? :score2i
|
102
|
-
@score2et = kwargs[:score2et] if kwargs.has_key? :score2et
|
103
|
-
@score2p = kwargs[:score2p] if kwargs.has_key? :score2p
|
104
|
-
@score2agg = kwargs[:score2agg] if kwargs.has_key? :score2agg
|
95
|
+
@score1 = kwargs[:score1] if kwargs.has_key?( :score1 )
|
96
|
+
@score1i = kwargs[:score1i] if kwargs.has_key?( :score1i )
|
97
|
+
@score1et = kwargs[:score1et] if kwargs.has_key?( :score1et )
|
98
|
+
@score1p = kwargs[:score1p] if kwargs.has_key?( :score1p )
|
99
|
+
@score1agg = kwargs[:score1agg] if kwargs.has_key?( :score1agg )
|
100
|
+
|
101
|
+
@score2 = kwargs[:score2] if kwargs.has_key?( :score2 )
|
102
|
+
@score2i = kwargs[:score2i] if kwargs.has_key?( :score2i )
|
103
|
+
@score2et = kwargs[:score2et] if kwargs.has_key?( :score2et )
|
104
|
+
@score2p = kwargs[:score2p] if kwargs.has_key?( :score2p )
|
105
|
+
@score2agg = kwargs[:score2agg] if kwargs.has_key?( :score2agg )
|
105
106
|
|
106
107
|
## note: (always) (auto-)convert scores to integers
|
107
108
|
@score1 = @score1.to_i if @score1
|
@@ -17,7 +17,20 @@ module Sports
|
|
17
17
|
@knockout = knockout
|
18
18
|
@auto = auto # auto-created (inline reference/header without proper definition before)
|
19
19
|
end
|
20
|
-
end # class Round
|
21
20
|
|
21
|
+
def pretty_print( printer )
|
22
|
+
## todo/check - how to display/format key - use () or not - why? why not?
|
23
|
+
buf = String.new
|
24
|
+
buf << "<Round: "
|
25
|
+
buf << "(#{@num}) " if @num
|
26
|
+
buf << "#{@name}, "
|
27
|
+
buf << "#{@start_date} - #{@end_date}"
|
28
|
+
buf << " (knockout)" if @knockout
|
29
|
+
buf << " (auto)" if @auto
|
30
|
+
buf << ">"
|
31
|
+
|
32
|
+
printer.text( buf )
|
33
|
+
end
|
34
|
+
end # class Round
|
22
35
|
end # module Sports
|
23
36
|
|
@@ -1,10 +1,8 @@
|
|
1
1
|
|
2
2
|
module Sports
|
3
3
|
|
4
|
-
##
|
5
|
-
## todo/fix: remove self.create in structs!!! use just new!!!
|
6
4
|
|
7
|
-
class Team
|
5
|
+
class Team # shared base for clubs AND natinal_teams
|
8
6
|
## todo: use just names for alt_names - why? why not?
|
9
7
|
attr_accessor :key, :name, :alt_names,
|
10
8
|
:code, ## code == abbreviation e.g. ARS etc.
|
@@ -20,18 +18,36 @@ class Team
|
|
20
18
|
def key
|
21
19
|
## note: auto-generate key "on-the-fly" if missing for now - why? why not?
|
22
20
|
## note: quick hack - auto-generate key, that is, remove all non-ascii chars and downcase
|
23
|
-
|
21
|
+
## fix update - allow numbers (0-9)
|
22
|
+
## add dash(-) plus parens () too!! for (-1999) or (1999-2011) or such
|
23
|
+
## add umlauts too for now - plus add more later!!!
|
24
|
+
##
|
25
|
+
## fix- add more (all) diacritics!!!
|
26
|
+
## GÍ Gøta (1926-2008)
|
27
|
+
## FC Suðuroy
|
28
|
+
## fix - remove dash(-) if not followed or preceded by year (four digits)!!!
|
29
|
+
##
|
30
|
+
## use new (autogen)key rule
|
31
|
+
## - 1st unaccent, 2nd downcase, 3rd remove space et al
|
32
|
+
## use keygen or autokey function or such - why? why not?
|
33
|
+
|
34
|
+
## cache autokey generation (elg. use ||= NOT ||) - why? why not?
|
35
|
+
|
36
|
+
@key ||= begin
|
37
|
+
unaccent( @name ).downcase.gsub( /[^a-z0-9()-]/, '' )
|
38
|
+
end
|
39
|
+
@key
|
24
40
|
end
|
25
41
|
|
26
42
|
|
27
43
|
## special import only attribs
|
28
|
-
attr_accessor :alt_names_auto ## auto-generated alt names
|
29
44
|
attr_accessor :wikipedia # wikipedia page name (for english (en))
|
30
45
|
|
31
46
|
|
32
47
|
def historic?() @year_end ? true : false; end
|
33
48
|
alias_method :past?, :historic?
|
34
49
|
|
50
|
+
|
35
51
|
def wikipedia?() @wikipedia; end
|
36
52
|
def wikipedia_url
|
37
53
|
if @wikipedia
|
@@ -48,52 +64,17 @@ class Team
|
|
48
64
|
|
49
65
|
def initialize( **kwargs )
|
50
66
|
@alt_names = []
|
51
|
-
|
52
|
-
|
67
|
+
|
53
68
|
update( **kwargs ) unless kwargs.empty?
|
54
69
|
end
|
55
70
|
|
56
71
|
def update( **kwargs )
|
57
|
-
@key = kwargs[:key] if kwargs.has_key? :key
|
58
|
-
@name = kwargs[:name] if kwargs.has_key? :name
|
59
|
-
@code = kwargs[:code] if kwargs.has_key? :code
|
60
|
-
@alt_names = kwargs[:alt_names] if kwargs.has_key? :alt_names
|
72
|
+
@key = kwargs[:key] if kwargs.has_key?( :key )
|
73
|
+
@name = kwargs[:name] if kwargs.has_key?( :name )
|
74
|
+
@code = kwargs[:code] if kwargs.has_key?( :code )
|
75
|
+
@alt_names = kwargs[:alt_names] if kwargs.has_key?( :alt_names )
|
61
76
|
self ## note - MUST return self for chaining
|
62
77
|
end
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
##############################
|
67
|
-
## helper methods for import only??
|
68
|
-
## check for duplicates
|
69
|
-
include SportDb::NameHelper
|
70
|
-
|
71
|
-
def duplicates?
|
72
|
-
names = [name] + alt_names + alt_names_auto
|
73
|
-
names = names.map { |name| normalize( sanitize(name) ) }
|
74
|
-
|
75
|
-
names.size != names.uniq.size
|
76
|
-
end
|
77
|
-
|
78
|
-
def duplicates
|
79
|
-
names = [name] + alt_names + alt_names_auto
|
80
|
-
|
81
|
-
## calculate (count) frequency and select if greater than one
|
82
|
-
names.reduce( {} ) do |h,name|
|
83
|
-
norm = normalize( sanitize(name) )
|
84
|
-
h[norm] ||= []
|
85
|
-
h[norm] << name; h
|
86
|
-
end.select { |norm,names| names.size > 1 }
|
87
|
-
end
|
88
|
-
|
89
|
-
|
90
|
-
def add_variants( name_or_names )
|
91
|
-
names = name_or_names.is_a?(Array) ? name_or_names : [name_or_names]
|
92
|
-
names.each do |name|
|
93
|
-
name = sanitize( name )
|
94
|
-
self.alt_names_auto += variants( name )
|
95
|
-
end
|
96
|
-
end
|
97
78
|
end # class Team
|
98
79
|
|
99
80
|
|
@@ -108,6 +89,15 @@ class NationalTeam < Team
|
|
108
89
|
self ## note - MUST return self for chaining
|
109
90
|
end
|
110
91
|
|
92
|
+
def pretty_print( printer )
|
93
|
+
buf = String.new
|
94
|
+
buf << "<NationalTeam: #{@name}"
|
95
|
+
## use code from country or from team ???
|
96
|
+
buf << " (#{@code})"
|
97
|
+
buf << ">"
|
98
|
+
|
99
|
+
printer.text( buf )
|
100
|
+
end
|
111
101
|
end # class NationalTeam
|
112
102
|
|
113
103
|
|
@@ -116,7 +106,8 @@ end # class NationalTeam
|
|
116
106
|
# district, geos, year_end, country, etc.
|
117
107
|
|
118
108
|
class Club < Team
|
119
|
-
attr_accessor
|
109
|
+
attr_accessor :address,
|
110
|
+
:ground
|
120
111
|
|
121
112
|
attr_accessor :a, :b
|
122
113
|
def a?() @a == nil; end ## is a (1st) team / club (i)? if a is NOT set
|
@@ -136,12 +127,22 @@ class Club < Team
|
|
136
127
|
|
137
128
|
def update( **kwargs )
|
138
129
|
super
|
139
|
-
@city = kwargs[:city] if kwargs.has_key? :city
|
130
|
+
@city = kwargs[:city] if kwargs.has_key?( :city )
|
140
131
|
## todo/fix: use city struct - why? why not?
|
141
132
|
## todo/fix: add country too or report unused keywords / attributes - why? why not?
|
142
133
|
|
143
134
|
self ## note - MUST return self for chaining
|
144
135
|
end
|
136
|
+
|
137
|
+
|
138
|
+
def pretty_print( printer )
|
139
|
+
buf = String.new
|
140
|
+
buf << "<Club: #{@name}"
|
141
|
+
buf << " (#{@country.code})" if @country
|
142
|
+
buf << ">"
|
143
|
+
|
144
|
+
printer.text( buf )
|
145
|
+
end
|
145
146
|
end # class Club
|
146
147
|
|
147
148
|
end # module Sports
|
@@ -3,8 +3,8 @@ module SportDb
|
|
3
3
|
module Module
|
4
4
|
module Structs
|
5
5
|
MAJOR = 0 ## todo: namespace inside version or something - why? why not??
|
6
|
-
MINOR =
|
7
|
-
PATCH =
|
6
|
+
MINOR = 2
|
7
|
+
PATCH = 0
|
8
8
|
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
9
9
|
|
10
10
|
def self.version
|
@@ -12,11 +12,11 @@ module SportDb
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def self.banner
|
15
|
-
"sportdb-structs/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
15
|
+
"sportdb-structs/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}] in (#{root})"
|
16
16
|
end
|
17
17
|
|
18
18
|
def self.root
|
19
|
-
File.expand_path( File.dirname(File.dirname(File.dirname(__FILE__))) )
|
19
|
+
File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )
|
20
20
|
end
|
21
21
|
|
22
22
|
end # module Structs
|
data/lib/sportdb/structs.rb
CHANGED
@@ -72,6 +72,45 @@ require 'sportdb/structs/structs/matchlist'
|
|
72
72
|
require 'sportdb/structs/structs/standings'
|
73
73
|
require 'sportdb/structs/structs/team_usage'
|
74
74
|
|
75
|
+
require 'sportdb/structs/structs/ground'
|
76
|
+
|
77
|
+
|
78
|
+
##
|
79
|
+
## todo/fix - move "inline" player to structs/player file !!!!
|
80
|
+
|
81
|
+
module Sports
|
82
|
+
### note - own classes for National(Squad)Player and
|
83
|
+
## Club(Squad)Player and such in use
|
84
|
+
|
85
|
+
class Player
|
86
|
+
attr_reader :name,
|
87
|
+
:pos, # position (g/d/m/f) for now
|
88
|
+
:nat, # nationality
|
89
|
+
:height, # in cm!! (integer) expected
|
90
|
+
:birthdate,
|
91
|
+
:birthplace
|
92
|
+
|
93
|
+
attr_accessor :alt_names
|
94
|
+
|
95
|
+
def initialize( name:,
|
96
|
+
pos: nil,
|
97
|
+
nat: nil,
|
98
|
+
height: nil,
|
99
|
+
birthdate: nil,
|
100
|
+
birthplace: nil )
|
101
|
+
@name = name
|
102
|
+
@alt_names = []
|
103
|
+
@pos = pos
|
104
|
+
@nat = nat
|
105
|
+
@height = height
|
106
|
+
@birthdate = birthdate
|
107
|
+
@birthplace = birthplace
|
108
|
+
end
|
109
|
+
end # class Player
|
110
|
+
end # module Sports
|
111
|
+
|
112
|
+
|
113
|
+
|
75
114
|
|
76
115
|
require 'sportdb/structs/match_status_parser'
|
77
116
|
require 'sportdb/structs/match_parser_csv'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sportdb-structs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.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:
|
11
|
+
date: 2024-06-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: alphabets
|
@@ -120,17 +120,17 @@ dependencies:
|
|
120
120
|
requirements:
|
121
121
|
- - "~>"
|
122
122
|
- !ruby/object:Gem::Version
|
123
|
-
version: '
|
123
|
+
version: '4.1'
|
124
124
|
type: :development
|
125
125
|
prerelease: false
|
126
126
|
version_requirements: !ruby/object:Gem::Requirement
|
127
127
|
requirements:
|
128
128
|
- - "~>"
|
129
129
|
- !ruby/object:Gem::Version
|
130
|
-
version: '
|
130
|
+
version: '4.1'
|
131
131
|
description: sportdb-structs - sport data structures for matches, scores, leagues,
|
132
132
|
seasons, rounds, groups, teams, clubs and more
|
133
|
-
email:
|
133
|
+
email: gerald.bauer@gmail.com
|
134
134
|
executables: []
|
135
135
|
extensions: []
|
136
136
|
extra_rdoc_files:
|
@@ -150,6 +150,7 @@ files:
|
|
150
150
|
- lib/sportdb/structs/name_helper.rb
|
151
151
|
- lib/sportdb/structs/structs/country.rb
|
152
152
|
- lib/sportdb/structs/structs/goal.rb
|
153
|
+
- lib/sportdb/structs/structs/ground.rb
|
153
154
|
- lib/sportdb/structs/structs/group.rb
|
154
155
|
- lib/sportdb/structs/structs/league.rb
|
155
156
|
- lib/sportdb/structs/structs/match.rb
|
@@ -159,12 +160,6 @@ files:
|
|
159
160
|
- lib/sportdb/structs/structs/team.rb
|
160
161
|
- lib/sportdb/structs/structs/team_usage.rb
|
161
162
|
- lib/sportdb/structs/version.rb
|
162
|
-
- test/helper.rb
|
163
|
-
- test/test_clubs.rb
|
164
|
-
- test/test_csv_reader.rb
|
165
|
-
- test/test_match.rb
|
166
|
-
- test/test_match_status_parser.rb
|
167
|
-
- test/test_name_helper.rb
|
168
163
|
homepage: https://github.com/sportdb/sport.db
|
169
164
|
licenses:
|
170
165
|
- Public Domain
|
@@ -186,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
186
181
|
- !ruby/object:Gem::Version
|
187
182
|
version: '0'
|
188
183
|
requirements: []
|
189
|
-
rubygems_version: 3.
|
184
|
+
rubygems_version: 3.4.10
|
190
185
|
signing_key:
|
191
186
|
specification_version: 4
|
192
187
|
summary: sportdb-structs - sport data structures for matches, scores, leagues, seasons,
|
data/test/helper.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
## note: use the local version of sportdb gems
|
2
|
-
$LOAD_PATH.unshift( File.expand_path( '../date-formats/lib' ))
|
3
|
-
$LOAD_PATH.unshift( File.expand_path( '../score-formats/lib' ))
|
4
|
-
$LOAD_PATH.unshift( File.expand_path( '../sportdb-langs/lib' ))
|
5
|
-
|
6
|
-
|
7
|
-
## minitest setup
|
8
|
-
require 'minitest/autorun'
|
9
|
-
|
10
|
-
|
11
|
-
## our own code
|
12
|
-
require 'sportdb/structs'
|
13
|
-
|
data/test/test_clubs.rb
DELETED
@@ -1,38 +0,0 @@
|
|
1
|
-
###
|
2
|
-
# to run use
|
3
|
-
# ruby -I ./lib -I ./test test/test_clubs.rb
|
4
|
-
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
|
8
|
-
class TestClubs < MiniTest::Test
|
9
|
-
|
10
|
-
Club = Sports::Club
|
11
|
-
|
12
|
-
|
13
|
-
def test_new
|
14
|
-
club = Club.new( name: 'Rapid Wien' )
|
15
|
-
|
16
|
-
assert_equal 'Rapid Wien', club.name
|
17
|
-
assert_equal ['Rapid Wien'], club.names
|
18
|
-
end
|
19
|
-
|
20
|
-
def test_duplicates
|
21
|
-
club = Club.new
|
22
|
-
club.name = 'Rapid Wien'
|
23
|
-
|
24
|
-
assert_equal false, club.duplicates?
|
25
|
-
duplicates = {}
|
26
|
-
assert_equal duplicates, club.duplicates
|
27
|
-
|
28
|
-
club.alt_names_auto += ['Rapid', 'Rapid Wien', 'SK Rapid Wien']
|
29
|
-
|
30
|
-
pp club
|
31
|
-
|
32
|
-
assert_equal true, club.duplicates?
|
33
|
-
duplicates = {'rapidwien'=>['Rapid Wien','Rapid Wien']}
|
34
|
-
pp club.duplicates
|
35
|
-
assert_equal duplicates, club.duplicates
|
36
|
-
end
|
37
|
-
|
38
|
-
end # class TestClubs
|
data/test/test_csv_reader.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
###
|
2
|
-
# to run use
|
3
|
-
# ruby -I ./lib -I ./test test/test_csv_reader.rb
|
4
|
-
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
|
8
|
-
|
9
|
-
class TestCsvReader < MiniTest::Test
|
10
|
-
|
11
|
-
def test_parse
|
12
|
-
recs = parse_csv( <<TXT )
|
13
|
-
### World Countries
|
14
|
-
|
15
|
-
Key, Code, Name
|
16
|
-
af, AFG, Afghanistan
|
17
|
-
al, ALB, Albania
|
18
|
-
dz, ALG, Algeria
|
19
|
-
as, ASA, American Samoa (US)
|
20
|
-
TXT
|
21
|
-
|
22
|
-
pp recs
|
23
|
-
assert_equal [{ 'Key' => 'af', 'Code' => 'AFG', 'Name' => 'Afghanistan'},
|
24
|
-
{ 'Key' => 'al', 'Code' => 'ALB', 'Name' => 'Albania'},
|
25
|
-
{ 'Key' => 'dz', 'Code' => 'ALG', 'Name' => 'Algeria'},
|
26
|
-
{ 'Key' => 'as', 'Code' => 'ASA', 'Name' => 'American Samoa (US)'},
|
27
|
-
], recs[0..3]
|
28
|
-
end
|
29
|
-
|
30
|
-
end # class TestCsvReader
|
data/test/test_match.rb
DELETED
@@ -1,30 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
###
|
4
|
-
# to run use
|
5
|
-
# ruby -I ./lib -I ./test test/test_match.rb
|
6
|
-
|
7
|
-
|
8
|
-
require 'helper'
|
9
|
-
|
10
|
-
class TestMatch < MiniTest::Test
|
11
|
-
|
12
|
-
Match = Sports::Match
|
13
|
-
|
14
|
-
|
15
|
-
def test_round
|
16
|
-
m = Match.new( team1: 'Team 1',
|
17
|
-
team2: 'Team 2',
|
18
|
-
round: 3 )
|
19
|
-
pp m
|
20
|
-
assert_equal 3, m.round
|
21
|
-
assert_nil m.score1
|
22
|
-
assert_nil m.score2
|
23
|
-
|
24
|
-
m = Match.new
|
25
|
-
m.update( round: 4 )
|
26
|
-
pp m
|
27
|
-
assert_equal 4, m.round
|
28
|
-
end # method test_round
|
29
|
-
|
30
|
-
end # class TestMatch
|
@@ -1,57 +0,0 @@
|
|
1
|
-
###
|
2
|
-
# to run use
|
3
|
-
# ruby -I ./lib -I ./test test/test_match_status_parser.rb
|
4
|
-
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
|
8
|
-
|
9
|
-
class TestMatchStatusParser < MiniTest::Test
|
10
|
-
|
11
|
-
Status = SportDb::Status
|
12
|
-
StatusParser = SportDb::StatusParser
|
13
|
-
|
14
|
-
def test_find
|
15
|
-
[['awarded [cancelled] canceled [ddd]', Status::CANCELLED],
|
16
|
-
['awarded [bbb; canceled] canceled [awarded; comments] eeee', Status::AWARDED],
|
17
|
-
['aaa bbb ccc ddd eeee', nil],
|
18
|
-
].each do |rec|
|
19
|
-
line = rec[0]
|
20
|
-
status_exp = rec[1]
|
21
|
-
puts "line (before): >#{line}<"
|
22
|
-
status = StatusParser.find!( line )
|
23
|
-
puts "status: >#{status}<"
|
24
|
-
puts "line (after): >#{line}<"
|
25
|
-
puts
|
26
|
-
|
27
|
-
if status_exp.nil?
|
28
|
-
assert_nil status
|
29
|
-
else
|
30
|
-
assert_equal status_exp, status
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end # method test_find
|
34
|
-
|
35
|
-
def test_parse
|
36
|
-
[['cancelled ddd', Status::CANCELLED],
|
37
|
-
['CANCELLED', Status::CANCELLED],
|
38
|
-
['can.', Status::CANCELLED],
|
39
|
-
['awarded; comments', Status::AWARDED],
|
40
|
-
['awd. - comments', Status::AWARDED],
|
41
|
-
['aaa bbb ccc ddd eeee', nil],
|
42
|
-
].each do |rec|
|
43
|
-
str = rec[0]
|
44
|
-
status_exp = rec[1]
|
45
|
-
status = StatusParser.parse( str )
|
46
|
-
|
47
|
-
if status_exp.nil? ## for "silencing" minitest warning - Use assert_nil if expecting nil
|
48
|
-
assert_nil status
|
49
|
-
else
|
50
|
-
assert_equal status_exp, status
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
end # class TestMatchStatusParser
|
56
|
-
|
57
|
-
|
data/test/test_name_helper.rb
DELETED
@@ -1,65 +0,0 @@
|
|
1
|
-
###
|
2
|
-
# to run use
|
3
|
-
# ruby -I ./lib -I ./test test/test_name_helper.rb
|
4
|
-
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
|
8
|
-
|
9
|
-
class TestNameHelper < MiniTest::Test
|
10
|
-
|
11
|
-
include SportDb::NameHelper
|
12
|
-
|
13
|
-
|
14
|
-
def test_strip_norm ## strip (remove) non-norm characters e.g. ()'- etc.
|
15
|
-
[['Estudiantes (LP)', 'Estudiantes LP'],
|
16
|
-
['Central Córdoba (SdE)', 'Central Córdoba SdE'],
|
17
|
-
['Saint Patrick’s Athletic FC', 'Saint Patricks Athletic FC'],
|
18
|
-
['Myllykosken Pallo −47', 'Myllykosken Pallo 47'],
|
19
|
-
].each do |rec|
|
20
|
-
assert_equal rec[1], strip_norm( rec[0] )
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def test_strip_year
|
25
|
-
[['A (1911-1912)', 'A'],
|
26
|
-
['B (1911-1912, 1913-1915)', 'B'],
|
27
|
-
['C (1911-___)', 'C'],
|
28
|
-
['D (1911-???)', 'D'],
|
29
|
-
['FC Linz (1946-2001, 2013-)', 'FC Linz'],
|
30
|
-
['Admira Wien (-????)', 'Admira Wien'],
|
31
|
-
['Admira Wien (-____)', 'Admira Wien'],
|
32
|
-
].each do |rec|
|
33
|
-
assert_equal rec[1], strip_year( rec[0] )
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_strip_lang
|
38
|
-
[['Bayern Munich [en]', 'Bayern Munich'],
|
39
|
-
].each do |rec|
|
40
|
-
assert_equal rec[1], strip_lang( rec[0] )
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
def test_variants
|
46
|
-
## hungarian
|
47
|
-
assert_equal ['Raba ETO Gyor'], variants( 'Rába ETO Győr' )
|
48
|
-
assert_equal ['Raba ETO Gyor', 'Rába ETO Gyoer'], variants( 'Rába ETO Györ' )
|
49
|
-
|
50
|
-
## romanian
|
51
|
-
assert_equal ['Targu Mures'], variants( 'Târgu Mureș' )
|
52
|
-
assert_equal ['Targu Mures'], variants( 'Târgu Mureş' )
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
=begin
|
57
|
-
### fix: move to ClubReader!!!!! not for general use
|
58
|
-
def test_wiki
|
59
|
-
assert_equal 'FC Wacker Innsbruck', strip_wiki( 'FC Wacker Innsbruck (2002)' )
|
60
|
-
assert_equal 'SK Austria Klagenfurt', strip_wiki( 'SK Austria Klagenfurt (2007)' )
|
61
|
-
|
62
|
-
assert_equal 'Willem II', strip_wiki( 'Willem II (football club)' )
|
63
|
-
end
|
64
|
-
=end
|
65
|
-
end # class TestNameHelper
|