sportdb-catalogs 1.2.2 → 1.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '09d5c1b4a2fea093abfc294ccbf6149315a335a07a5e934d25fb652215e0ab23'
4
- data.tar.gz: 991f6cd9ee018fa4f7d84be847c5868a024ac240ec5d29cb60636addbd1984c5
3
+ metadata.gz: 6fc1b8889790b051b658712c11580c31972e49b1efd04e3bd5fad1fefaec44b1
4
+ data.tar.gz: 5036274f73ee73e8275a49fbbc5f9192eee317baf4f63d70f1dd6ca48def86c8
5
5
  SHA512:
6
- metadata.gz: ffaca4423b4dc8adba0db61187dfcf2cc0b1fb5c47255953ed08e8e13bc1a0e2967673d7f1a60f5d6a7045b93ff3575fc27114ed86be15c27f72041287e59a91
7
- data.tar.gz: ded797ffeae2ce160c1d6477416fa90d8b26433e78aca4bdc61c82bf0bdf8eef95f346c2f2fe95e070be962d8789d511d222379057245a9d649388b0a40d93c1
6
+ metadata.gz: 7f104ef1fa0f0711403386a9a23313055fd67288eeeba564baf52e03c86d1f6851136b8bdde95b462b97bc5756dc06c5ed298776b61b66ca25edab248c4ea7da
7
+ data.tar.gz: 3ad50ff5c3fe022ff5e36ec3d3e03503bffe8c1c1475559a7e84cdc8929bb5fd0a88b3fd095b57192cd306937b10194b7c66f250c2b11a0b4d7c80f224e041b2
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 1.2.2
1
+ ### 1.2.4
2
2
  ### 0.0.1 / 2019-06-29
3
3
 
4
4
  * Everything is new. First release.
data/README.md CHANGED
@@ -11,66 +11,8 @@
11
11
 
12
12
  ## Usage
13
13
 
14
- Let's use the [/clubs datasets](https://github.com/openfootball/clubs)
15
- (3000+ football clubs from around the world)
16
- to match name "variants" e.g. `Arsenal` to canonical global unique
17
- names e.g. `Arsenal FC, London, England`:
18
14
 
19
- ``` ruby
20
- require 'sportdb/catalogs'
21
-
22
- Club = CatalogDb::Metal::Club
23
-
24
- m = Club.match_by( name: 'Arsenal' )
25
- m.size # 3 club matches found
26
- #=> 3
27
- m[0].name; m[0].city; m[0].country
28
- #=> "Arsenal FC", "London", "England"
29
- m[1].name; m[1].city; m[1].country
30
- #=> "Arsenal Tula", "Tula", "Russia"
31
- m[2].name; m[2].city; m[2].country
32
- #=> "Arsenal de Sarandí", "Sarandí", "Argentina"
33
-
34
-
35
- m = Club.match_by( name: 'Arsenal', country: 'eng' )
36
- # -or- try alternative names (and auto-generated spelling variants)
37
- m = Club.match_by( name: 'Arsenal FC', country: 'eng' )
38
- m = Club.match_by( name: 'Arsenal F.C.', country: 'eng' )
39
- m = Club.match_by( name: '...A.r.s.e.n.a.l... F.C...', country: 'eng' )
40
- m.size # 1 club match found
41
- #=> 1
42
- m[0].name; m[0].city; m[0].country
43
- #=> "Arsenal FC", "London", "England"
44
-
45
- m = Club.match_by( name: 'Arsenal', country: 'ar' )
46
- # -or- try alternative names (and auto-generated spelling variants)
47
- m = Club.match_by( name: 'Arsenal Sarandí', country: 'ar' )
48
- m = Club.match_by( name: 'Arsenal Sarandi', country: 'ar' )
49
- m.size # 1 club match found
50
- #=> 1
51
- m[0].name; m[0].city; m[0].country
52
- #=> "Arsenal de Sarandí", "Sarandí", "Argentina"
53
-
54
-
55
- # try some more
56
- m = Club.match_by( name: 'AZ' )
57
- m[0].name; m[0].city; m[0].country
58
- #=> "AZ Alkmaar", "Alkmaar", "Netherlands"
59
-
60
- m = Club.match_by( name: 'Bayern' )
61
- # -or- try alternative names (and auto-generated spelling variants)
62
- m = Club.match_by( name: 'Bayern München' )
63
- m = Club.match_by( name: 'Bayern Munchen' )
64
- m = Club.match_by( name: 'Bayern Muenchen' )
65
- m[0].name; m[0].city; m[0].country
66
- #=> "Bayern München", "München", "Germany"
67
-
68
- # and so on
69
- # ...
70
- ```
71
-
72
-
73
- That's it.
15
+ to be done
74
16
 
75
17
 
76
18
 
data/Rakefile CHANGED
@@ -22,7 +22,7 @@ Hoe.spec 'sportdb-catalogs' do
22
22
  self.extra_deps = [
23
23
  ['sportdb-structs', '>= 0.3.1'],
24
24
  ['sqlite3'], ## add sqlite for "metal" use (no activerecord etc.)
25
- ['footballdb-data'] ## add builtin default db
25
+ ['footballdb-data', '>= 2024.8.23'] ## add builtin default db
26
26
  ]
27
27
 
28
28
  self.spec_extras = {
@@ -155,6 +155,29 @@ def self._city( city )
155
155
  city ## (re)use city struct - no need to run lookup again
156
156
  end
157
157
  end
158
+
159
+
160
+ def self._league( league )
161
+ if league.is_a?( String ) || league.is_a?( Symbol )
162
+ # note: query/find country via catalog db
163
+ ## only query by code - why? why not?
164
+ recs = League.match_by_name_or_code( league )
165
+ if recs.empty?
166
+ puts "** !!! ERROR !!! - unknown league >#{league}< - no match found, sorry"
167
+ exit 1
168
+ elsif recs.size > 1
169
+ puts "** !!! ERROR !!! - league >#{league}< - too many matches found (#{recs.size}), sorry"
170
+ pp recs
171
+ exit 1
172
+ end
173
+ recs[0]
174
+ else ## assume league struct
175
+ league ## (re)use league struct - no need to run lookup again
176
+ end
177
+ end
178
+
179
+
180
+
158
181
  end # class Record
159
182
 
160
183
 
@@ -16,7 +16,10 @@ class EventInfo < Record
16
16
  def self._build_event_info( row )
17
17
  ## note: cache structs by key (do NOT rebuild duplicates; reuse)
18
18
  @cache ||= Hash.new
19
- @cache[ row[0] ] ||= Sports::EventInfo.new(
19
+ ## note cache key MUST be unique!
20
+ ## use league PLUS season (row[0] season only will NOT work)
21
+ key = "#{row[0]}_#{row[1]}"
22
+ @cache[ key ] ||= Sports::EventInfo.new(
20
23
  league: _to_league( row[0] ),
21
24
  season: Season.parse(row[1]),
22
25
  teams: row[2],
@@ -29,8 +32,7 @@ class EventInfo < Record
29
32
 
30
33
 
31
34
  def self.seasons( league )
32
- league_key = league.is_a?( String ) ? League.find!( league ).key
33
- : league.key
35
+ league_key = _league( league ).key
34
36
 
35
37
  rows = execute( <<-SQL )
36
38
  SELECT #{self.columns.join(', ')}
@@ -43,8 +45,7 @@ SQL
43
45
 
44
46
 
45
47
  def self.find_by( league:, season: )
46
- league_key = league.is_a?( String ) ? League.find!( league ).key
47
- : league.key
48
+ league_key = _league( league ).key
48
49
  season_key = season.is_a?( String ) ? Season.parse(season).key
49
50
  : season.key
50
51
 
@@ -50,7 +50,7 @@ SQL
50
50
  ### todo/fix: allow special normalize formula for
51
51
  ## code - why? why not?
52
52
  ## e.g. allow ö1 or ö or such - why? why not?
53
- code = normalize( unaccent(code) )
53
+ code = normalize( code )
54
54
 
55
55
  rows = nil
56
56
  if country.nil?
@@ -120,7 +120,7 @@ SQL
120
120
  def self.match_by_name_or_code( q,
121
121
  country: nil )
122
122
  name = normalize( unaccent(q) )
123
- code = normalize( unaccent(q) )
123
+ code = normalize( q )
124
124
 
125
125
  rows = nil
126
126
  if country.nil?
@@ -5,7 +5,7 @@ module Catalogs
5
5
 
6
6
  MAJOR = 1 ## todo: namespace inside version or something - why? why not??
7
7
  MINOR = 2
8
- PATCH = 2
8
+ PATCH = 4
9
9
  VERSION = [MAJOR,MINOR,PATCH].join('.')
10
10
 
11
11
  def self.version
@@ -15,6 +15,7 @@ require_relative 'catalogs/city'
15
15
  require_relative 'catalogs/club'
16
16
  require_relative 'catalogs/national_team'
17
17
  require_relative 'catalogs/league'
18
+ require_relative 'catalogs/league_period'
18
19
  require_relative 'catalogs/event_info'
19
20
  require_relative 'catalogs/ground'
20
21
 
@@ -44,7 +45,7 @@ def self.tables
44
45
  ## puts
45
46
  puts " #{Country.count} countries / #{City.count} cities"
46
47
  puts " #{NationalTeam.count} national teams"
47
- puts " #{League.count} leagues"
48
+ puts " #{League.count} leagues / #{LeaguePeriod.count} periods"
48
49
  puts " #{Club.count} clubs"
49
50
  puts " #{Ground.count} grounds"
50
51
  ## add more
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-catalogs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.2.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-23 00:00:00.000000000 Z
11
+ date: 2024-10-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-structs
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 2024.8.23
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 2024.8.23
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rdoc
57
57
  requirement: !ruby/object:Gem::Requirement