footballdb-clubs 2019.11.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/Manifest.txt +10 -0
- data/README.md +178 -0
- data/Rakefile +31 -0
- data/config/clubs.txt +5856 -0
- data/config/clubs.wiki.txt +738 -0
- data/lib/footballdb/clubs.rb +78 -0
- data/lib/footballdb/clubs/version.rb +29 -0
- data/test/helper.rb +10 -0
- data/test/test_club.rb +97 -0
- metadata +116 -0
@@ -0,0 +1,78 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
###
|
5
|
+
# sport.db gems / libraries
|
6
|
+
require 'fifa'
|
7
|
+
require 'sportdb/clubs'
|
8
|
+
|
9
|
+
|
10
|
+
###
|
11
|
+
# our own code
|
12
|
+
require 'footballdb/clubs/version' # let version always go first
|
13
|
+
|
14
|
+
|
15
|
+
module FootballDb
|
16
|
+
module Import
|
17
|
+
|
18
|
+
## add "fake" configuration for stand-alone usage
|
19
|
+
class Configuration
|
20
|
+
def initialize
|
21
|
+
recs = Fifa.countries
|
22
|
+
@countries = SportDb::Import::CountryIndex.new( recs )
|
23
|
+
end
|
24
|
+
|
25
|
+
def countries() @countries; end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
class Club ## todo/check: use a module instead of class - why? why not?
|
32
|
+
def self.clubs() club_index.clubs; end ## return all clubs (struct-like) records
|
33
|
+
def self.all() clubs; end ## use ActiveRecord-like alias for clubs
|
34
|
+
|
35
|
+
def self.mappings() club_index.mappings; end
|
36
|
+
|
37
|
+
def self.[]( name ) club_index[ name ]; end ## lookup by canoncial name only
|
38
|
+
def self.match( name ) club_index.match( name ); end
|
39
|
+
def self.match_by( name:, country: ) club_index.match_by( name: name, country: country ); end
|
40
|
+
|
41
|
+
|
42
|
+
def self.club_index
|
43
|
+
@club_index ||= build_club_index
|
44
|
+
@club_index
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
def self.build_club_index
|
49
|
+
if defined?( SportDb::Import::Configuration )
|
50
|
+
# assume running "inside" sportdb - (re)use sportdb configuration
|
51
|
+
else
|
52
|
+
# assume running "stand-alone" - setup configuration for countries / country mapping
|
53
|
+
config = Configuration.new
|
54
|
+
SportDb::Import::ClubReader.config = config
|
55
|
+
SportDb::Import::ClubIndex.config = config
|
56
|
+
SportDb::Import::WikiReader.config = config
|
57
|
+
end
|
58
|
+
|
59
|
+
recs = SportDb::Import::ClubReader.read( "#{FootballDb::Clubs.data_dir}/clubs.txt" )
|
60
|
+
club_index = SportDb::Import::ClubIndex.new
|
61
|
+
club_index.add( recs )
|
62
|
+
recs = SportDb::Import::WikiReader.read( "#{FootballDb::Clubs.data_dir}/clubs.wiki.txt" )
|
63
|
+
club_index.add_wiki( recs )
|
64
|
+
club_index
|
65
|
+
end
|
66
|
+
end # class Club
|
67
|
+
|
68
|
+
end # module Import
|
69
|
+
end # module FootballDb
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
### add top-level (global) convenience alias
|
74
|
+
Club = FootballDb::Import::Club
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
puts FootballDb::Clubs.banner # say hello
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
|
4
|
+
module FootballDb
|
5
|
+
module Clubs
|
6
|
+
|
7
|
+
MAJOR = 2019 ## todo: namespace inside version or something - why? why not??
|
8
|
+
MINOR = 11
|
9
|
+
PATCH = 22
|
10
|
+
VERSION = [MAJOR,MINOR,PATCH].join('.')
|
11
|
+
|
12
|
+
def self.version
|
13
|
+
VERSION
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.banner
|
17
|
+
"footballdb-clubs/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.root
|
21
|
+
File.expand_path( File.dirname(File.dirname(File.dirname(File.dirname(__FILE__)))) )
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.data_dir ## rename to config_dir - why? why not?
|
25
|
+
"#{root}/config"
|
26
|
+
end
|
27
|
+
|
28
|
+
end # module Clubs
|
29
|
+
end # module FootballDb
|
data/test/helper.rb
ADDED
data/test/test_club.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
###
|
4
|
+
# to run use
|
5
|
+
# ruby -I ./lib -I ./test test/test_club.rb
|
6
|
+
|
7
|
+
|
8
|
+
require 'helper'
|
9
|
+
|
10
|
+
class TestClub < MiniTest::Test
|
11
|
+
|
12
|
+
def test_match
|
13
|
+
|
14
|
+
m = Club.match( 'Rapid Wien' )
|
15
|
+
assert_equal 'SK Rapid Wien', m[0].name
|
16
|
+
assert_equal 'Austria', m[0].country.name
|
17
|
+
assert_equal 'Wien', m[0].city
|
18
|
+
|
19
|
+
m = Club.match( 'rapid wien' )
|
20
|
+
assert_equal 'SK Rapid Wien', m[0].name
|
21
|
+
assert_equal 'Austria', m[0].country.name
|
22
|
+
assert_equal 'Wien', m[0].city
|
23
|
+
|
24
|
+
## note: all dots (.) get always removed
|
25
|
+
m = Club.match( '...r.a.p.i.d w.i.e.n...' )
|
26
|
+
assert_equal 'SK Rapid Wien', m[0].name
|
27
|
+
assert_equal 'Austria', m[0].country.name
|
28
|
+
assert_equal 'Wien', m[0].city
|
29
|
+
|
30
|
+
## note: all spaces and dashes (-) get always removed
|
31
|
+
m = Club.match( '--- r a p i d w i e n ---' )
|
32
|
+
assert_equal 'SK Rapid Wien', m[0].name
|
33
|
+
assert_equal 'Austria', m[0].country.name
|
34
|
+
assert_equal 'Wien', m[0].city
|
35
|
+
|
36
|
+
m = Club.match( 'RAPID WIEN' )
|
37
|
+
assert_equal 'SK Rapid Wien', m[0].name
|
38
|
+
assert_equal 'Austria', m[0].country.name
|
39
|
+
assert_equal 'Wien', m[0].city
|
40
|
+
|
41
|
+
|
42
|
+
c = Club[ 'SK Rapid Wien' ] ## check canoncial name match (only)
|
43
|
+
assert_equal 'SK Rapid Wien', c.name
|
44
|
+
assert_equal 'Austria', c.country.name
|
45
|
+
assert_equal 'Wien', c.city
|
46
|
+
|
47
|
+
|
48
|
+
m = Club.match( 'Arsenal' )
|
49
|
+
assert_equal 3, m.size
|
50
|
+
|
51
|
+
m = Club.match( 'ARSENAL' )
|
52
|
+
assert_equal 3, m.size
|
53
|
+
|
54
|
+
m = Club.match_by( name: 'Arsenal', country: 'eng' )
|
55
|
+
assert_equal 1, m.size
|
56
|
+
assert_equal 'Arsenal FC', m[0].name
|
57
|
+
assert_equal 'England', m[0].country.name
|
58
|
+
assert_equal 'London', m[0].city
|
59
|
+
|
60
|
+
m = Club.match_by( name: 'Arsenal', country: 'ar' )
|
61
|
+
assert_equal 1, m.size
|
62
|
+
assert_equal 'Arsenal de Sarandí', m[0].name
|
63
|
+
assert_equal 'Argentina', m[0].country.name
|
64
|
+
assert_equal 'Sarandí', m[0].city
|
65
|
+
|
66
|
+
m = Club.match_by( name: 'Arsenal', country: 'ru' )
|
67
|
+
assert_equal 1, m.size
|
68
|
+
assert_equal 'Arsenal Tula', m[0].name
|
69
|
+
assert_equal 'Russia', m[0].country.name
|
70
|
+
assert_equal 'Tula', m[0].city
|
71
|
+
|
72
|
+
|
73
|
+
m = Club.match( 'Arsenal FC' )
|
74
|
+
assert_equal 2, m.size
|
75
|
+
|
76
|
+
m = Club.match( 'Arsenal F.C.' )
|
77
|
+
assert_equal 2, m.size
|
78
|
+
|
79
|
+
m = Club.match( '...A.r.s.e.n.a.l... F.C...' )
|
80
|
+
assert_equal 2, m.size
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
def test_wikipedia # test wikipedia names and links/urls
|
85
|
+
|
86
|
+
m = Club.match( 'Club Brugge KV' )
|
87
|
+
assert_equal 1, m.size
|
88
|
+
assert_equal 'Club Brugge KV', m[0].wikipedia
|
89
|
+
assert_equal 'https://en.wikipedia.org/wiki/Club_Brugge_KV', m[0].wikipedia_url
|
90
|
+
|
91
|
+
m = Club.match( 'RSC Anderlecht' )
|
92
|
+
assert_equal 1, m.size
|
93
|
+
assert_equal 'R.S.C. Anderlecht', m[0].wikipedia
|
94
|
+
assert_equal 'https://en.wikipedia.org/wiki/R.S.C._Anderlecht', m[0].wikipedia_url
|
95
|
+
end
|
96
|
+
|
97
|
+
end # class TestClub
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: footballdb-clubs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2019.11.22
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Gerald Bauer
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-11-22 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sportdb-clubs
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: fifa
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rdoc
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '4.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '4.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: hoe
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.16'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.16'
|
69
|
+
description: footballdb-clubs - the world's top football clubs
|
70
|
+
email: opensport@googlegroups.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files:
|
74
|
+
- CHANGELOG.md
|
75
|
+
- Manifest.txt
|
76
|
+
- README.md
|
77
|
+
- config/clubs.txt
|
78
|
+
- config/clubs.wiki.txt
|
79
|
+
files:
|
80
|
+
- CHANGELOG.md
|
81
|
+
- Manifest.txt
|
82
|
+
- README.md
|
83
|
+
- Rakefile
|
84
|
+
- config/clubs.txt
|
85
|
+
- config/clubs.wiki.txt
|
86
|
+
- lib/footballdb/clubs.rb
|
87
|
+
- lib/footballdb/clubs/version.rb
|
88
|
+
- test/helper.rb
|
89
|
+
- test/test_club.rb
|
90
|
+
homepage: https://github.com/sportdb/sport.db
|
91
|
+
licenses:
|
92
|
+
- Public Domain
|
93
|
+
metadata: {}
|
94
|
+
post_install_message:
|
95
|
+
rdoc_options:
|
96
|
+
- "--main"
|
97
|
+
- README.md
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 2.2.2
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.5.2
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: footballdb-clubs - the world's top football clubs
|
116
|
+
test_files: []
|