sportdb-catalogs 1.2.5 → 1.2.6

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: ed0f3720e4ff002df8ac2d14305f3ed147656d45ce4dc2c7770a3e8057f95439
4
- data.tar.gz: 8c1a5d9f32172cffbe7b4376d00af7c3f0d463ee8bd3e979ec6cc2d7949168d9
3
+ metadata.gz: 578a7aa88076914972bfeecf0bf244bcd33c2b14e22ba2032419d7d90aedd2d2
4
+ data.tar.gz: 755ff971b5e0dd2f63a91ffe6ed09dbaf96e856327c1a66f4531e55f91dd8e3f
5
5
  SHA512:
6
- metadata.gz: 50c14e72e5f993b4d66769da4190722b125db6ba1dbd914526c7bdb01f546d13f4a498fd8fd70d251e6898aa08692e000c8e5be7dd69e1d2fc42066d8ce91e1a
7
- data.tar.gz: d7a5f124e35a59b7daa72b0b99947ee4b6f6d0a5e15138638ce18cc883e7f3507de07a54df2d11437ceafd6acaa81749dfdc481d112738da82560262b4394121
6
+ metadata.gz: 1883983c41e1cc509e0a2b939bc59c70896602d6fb1e3c3f8943fc4c67115f680d09d5813a37d6215c61062352a2fad13169255d7df032ecd6beb91730ab52fd
7
+ data.tar.gz: 3ffa1b429634885daad9e7f46e61c9c3d81f4b799edbe6591a9c49c5c8260d5ed5b37799825d720f3aff27ab420f0f65fdf6621a14cd8f978199839def029094
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 1.2.5
1
+ ### 1.2.6
2
2
  ### 0.0.1 / 2019-06-29
3
3
 
4
4
  * Everything is new. First release.
data/Rakefile CHANGED
@@ -20,9 +20,9 @@ Hoe.spec 'sportdb-catalogs' do
20
20
  self.licenses = ['Public Domain']
21
21
 
22
22
  self.extra_deps = [
23
- ['sportdb-structs', '>= 0.3.1'],
23
+ ['sportdb-structs', '>= 0.5.0'],
24
+ ['footballdb-data', '>= 2025.1.3'], ## add builtin default db
24
25
  ['sqlite3'], ## add sqlite for "metal" use (no activerecord etc.)
25
- ['footballdb-data', '>= 2024.8.23'] ## add builtin default db
26
26
  ]
27
27
 
28
28
  self.spec_extras = {
@@ -44,44 +44,78 @@ SQL
44
44
  )
45
45
  end
46
46
 
47
+
48
+ def self._query_by_code( code: )
49
+ execute( <<-SQL )
50
+ SELECT #{self.columns.join(', ')}
51
+ FROM leagues
52
+ INNER JOIN league_codes ON leagues.key = league_codes.key
53
+ WHERE league_codes.code = '#{code}'
54
+ SQL
55
+ end
56
+
57
+ def self._query_by_code_and_country( code:, country: )
58
+ execute( <<-SQL )
59
+ SELECT #{self.columns.join(', ')}
60
+ FROM leagues
61
+ INNER JOIN league_codes ON leagues.key = league_codes.key
62
+ WHERE league_codes.code = '#{code}' AND
63
+ leagues.country_key = '#{country}'
64
+ SQL
65
+ end
66
+
67
+ def self._query_by_code_and_season( code:, start_yyyymm:,
68
+ end_yyyymm: )
69
+ execute( <<-SQL )
70
+ SELECT #{self.columns.join(', ')}
71
+ FROM leagues
72
+ WHERE leagues.key IN
73
+ (SELECT league_periods.key
74
+ FROM league_periods
75
+ INNER JOIN league_period_codes ON league_periods.id = league_period_codes.league_period_id
76
+ WHERE league_period_codes.code = '#{code}' AND
77
+ league_period_codes.start_yyyymm <= #{start_yyyymm} AND
78
+ league_period_codes.end_yyyymm >= #{end_yyyymm}
79
+ )
80
+ SQL
81
+ end
82
+
83
+
84
+
47
85
  def self.match_by_code( code,
48
- country: nil )
86
+ country: nil,
87
+ season: nil )
49
88
  ## note: match must for now always include name
50
89
  ### todo/fix: allow special normalize formula for
51
90
  ## code - why? why not?
52
91
  ## e.g. allow ö1 or ö or such - why? why not?
53
92
  code = normalize( code )
54
93
 
55
- rows = nil
56
- if country.nil?
57
- ## note: returns empty array if no match and NOT nil
58
- rows = execute( <<-SQL )
59
- SELECT #{self.columns.join(', ')}
60
- FROM leagues
61
- INNER JOIN league_codes ON leagues.key = league_codes.key
62
- WHERE league_codes.code = '#{code}'
63
- SQL
64
- else ## filter by country
65
- ## note: also skip international leagues & cups (e.g. champions league etc.) for now - why? why not?
66
-
67
- ## note: country assumes / allows the country key or fifa code for now
68
- ## note: allow passing in of country struct too
69
- country_rec = _country( country )
70
-
71
- rows = execute( <<-SQL )
72
- SELECT #{self.columns.join(', ')}
73
- FROM leagues
74
- INNER JOIN league_codes ON leagues.key = league_codes.key
75
- WHERE league_codes.code = '#{code}' AND
76
- leagues.country_key = '#{country_rec.key}'
77
-
78
- SQL
79
- end
94
+
95
+ rows = if country.nil? && season.nil?
96
+ ## note: returns empty array if no match and NOT nil
97
+ _query_by_code( code: code )
98
+ elsif country && season.nil? ## filter by country
99
+ ## note: also skip international leagues & cups (e.g. champions league etc.) for now - why? why not?
100
+
101
+ ## note: country assumes / allows the country key or fifa code for now
102
+ ## note: allow passing in of country struct too
103
+ country_rec = _country( country )
104
+ _query_by_code_and_country( code: code, country: country_rec.key )
105
+ elsif season && country.nil?
106
+ season = Season( season )
107
+ start_yyyymm, end_yyyymm = _calc_yyyymm( season )
108
+ _query_by_code_and_season( code: code, start_yyyymm: start_yyyymm,
109
+ end_yyyymm: end_yyyymm )
110
+ else
111
+ raise ArgumentError, "match_by_code - code and optional country or season expected"
112
+ end
80
113
 
81
114
  ## wrap results array into struct records
82
115
  rows.map {|row| _build_league( row )}
83
116
  end
84
117
 
118
+
85
119
  def self.match_by_name( name,
86
120
  country: nil )
87
121
  ## note: match must for now always include name
@@ -163,6 +197,28 @@ SQL
163
197
  end
164
198
 
165
199
 
200
+
201
+ ##############################################
202
+ # try match by code and seaons (via league_periods)
203
+ ## todo/fix - move up for reuse (duplicated in league_period etc) - why? why not?
204
+
205
+ def self._calc_yyyymm( season )
206
+ start_yyyymm = if season.calendar?
207
+ "#{season.start_year}01".to_i
208
+ else
209
+ "#{season.start_year}07".to_i
210
+ end
211
+
212
+ end_yyyymm = if season.calendar?
213
+ "#{season.end_year}12".to_i
214
+ else
215
+ "#{season.end_year}06".to_i
216
+ end
217
+
218
+ [start_yyyymm, end_yyyymm]
219
+ end
220
+
221
+
166
222
  end # class League
167
223
  end # module Metal
168
224
  end # module CatalogDb
@@ -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 = 5
8
+ PATCH = 6
9
9
  VERSION = [MAJOR,MINOR,PATCH].join('.')
10
10
 
11
11
  def self.version
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.5
4
+ version: 1.2.6
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-10-21 00:00:00.000000000 Z
11
+ date: 2025-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-structs
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 0.3.1
19
+ version: 0.5.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.3.1
26
+ version: 0.5.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: sqlite3
28
+ name: footballdb-data
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 2025.1.3
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 2025.1.3
41
41
  - !ruby/object:Gem::Dependency
42
- name: footballdb-data
42
+ name: sqlite3
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: 2024.8.23
47
+ version: '0'
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: 2024.8.23
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rdoc
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -78,14 +78,14 @@ dependencies:
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '4.1'
81
+ version: '4.2'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '4.1'
88
+ version: '4.2'
89
89
  description: sportdb-catalogs - sport.db (search 'n' find) catalogs for countries,
90
90
  leagues, clubs, national teams, and more
91
91
  email: gerald.bauer@gmail.com
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
135
  requirements: []
136
- rubygems_version: 3.4.10
136
+ rubygems_version: 3.5.22
137
137
  signing_key:
138
138
  specification_version: 4
139
139
  summary: sportdb-catalogs - sport.db (search 'n' find) catalogs for countries, leagues,