sportdb-catalogs 1.2.4 → 1.2.5

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: 6fc1b8889790b051b658712c11580c31972e49b1efd04e3bd5fad1fefaec44b1
4
- data.tar.gz: 5036274f73ee73e8275a49fbbc5f9192eee317baf4f63d70f1dd6ca48def86c8
3
+ metadata.gz: ed0f3720e4ff002df8ac2d14305f3ed147656d45ce4dc2c7770a3e8057f95439
4
+ data.tar.gz: 8c1a5d9f32172cffbe7b4376d00af7c3f0d463ee8bd3e979ec6cc2d7949168d9
5
5
  SHA512:
6
- metadata.gz: 7f104ef1fa0f0711403386a9a23313055fd67288eeeba564baf52e03c86d1f6851136b8bdde95b462b97bc5756dc06c5ed298776b61b66ca25edab248c4ea7da
7
- data.tar.gz: 3ad50ff5c3fe022ff5e36ec3d3e03503bffe8c1c1475559a7e84cdc8929bb5fd0a88b3fd095b57192cd306937b10194b7c66f250c2b11a0b4d7c80f224e041b2
6
+ metadata.gz: 50c14e72e5f993b4d66769da4190722b125db6ba1dbd914526c7bdb01f546d13f4a498fd8fd70d251e6898aa08692e000c8e5be7dd69e1d2fc42066d8ce91e1a
7
+ data.tar.gz: d7a5f124e35a59b7daa72b0b99947ee4b6f6d0a5e15138638ce18cc883e7f3507de07a54df2d11437ceafd6acaa81749dfdc481d112738da82560262b4394121
data/CHANGELOG.md CHANGED
@@ -1,4 +1,4 @@
1
- ### 1.2.4
1
+ ### 1.2.5
2
2
  ### 0.0.1 / 2019-06-29
3
3
 
4
4
  * Everything is new. First release.
data/Manifest.txt CHANGED
@@ -10,6 +10,7 @@ lib/sportdb/catalogs/country.rb
10
10
  lib/sportdb/catalogs/event_info.rb
11
11
  lib/sportdb/catalogs/ground.rb
12
12
  lib/sportdb/catalogs/league.rb
13
+ lib/sportdb/catalogs/league_period.rb
13
14
  lib/sportdb/catalogs/national_team.rb
14
15
  lib/sportdb/catalogs/player.rb
15
16
  lib/sportdb/catalogs/version.rb
@@ -0,0 +1,151 @@
1
+ module CatalogDb
2
+ module Metal
3
+
4
+ class LeaguePeriod < Record
5
+ self.tablename = 'league_periods'
6
+
7
+ self.columns = ['id',
8
+ 'key', ## league foreign refkey!!!
9
+ 'tier_key', ## change to code - why? why not?
10
+ 'name',
11
+ 'qname',
12
+ 'slug',
13
+ 'start_season',
14
+ 'end_season']
15
+
16
+
17
+ def self.cache() @cache ||= Hash.new; end
18
+
19
+
20
+ def self._record( id ) ## use _record! as name - why? why not?
21
+ if (rec = cache[ id ])
22
+ rec ## return cached
23
+ else ## query and cache and return
24
+ rows = execute( <<-SQL )
25
+ SELECT #{self.columns.join(', ')}
26
+ FROM league_periods
27
+ WHERE leagues_periods.id = #{id}
28
+ SQL
29
+
30
+ ## todo/fix: also assert for rows == 1 AND NOT MULTIPLE records - why? why not?
31
+ if rows.empty?
32
+ raise ArgumentError, "league period record with id #{id} not found"
33
+ else
34
+ _build_league_period( rows[0] )
35
+ end
36
+ end
37
+ end
38
+
39
+
40
+ def self._build_league_period( row )
41
+ ## get league record by ky
42
+ ## league = League._record( row[1] )
43
+
44
+ ## note: cache structs by key (do NOT rebuild duplicates; reuse)
45
+ cache[ row[0] ] ||= Sports::LeaguePeriod.new(
46
+ key: row[2], ## tier key
47
+ name: row[3],
48
+ qname: row[4],
49
+ slug: row[5],
50
+ start_season: row[6] ? Season.parse( row[6]) : nil,
51
+ end_season: row[7] ? Season.parse( row[7]) : nil
52
+ )
53
+ end
54
+
55
+
56
+ def self._calc_yyyymm( season )
57
+ start_yyyymm = if season.calendar?
58
+ "#{season.start_year}01".to_i
59
+ else
60
+ "#{season.start_year}07".to_i
61
+ end
62
+
63
+ end_yyyymm = if season.calendar?
64
+ "#{season.end_year}12".to_i
65
+ else
66
+ "#{season.end_year}06".to_i
67
+ end
68
+
69
+ [start_yyyymm, end_yyyymm]
70
+ end
71
+
72
+
73
+ def self.match_by_code( code, season: )
74
+ code = normalize( code )
75
+
76
+ season = Season( season )
77
+ start_yyyymm, end_yyyymm = _calc_yyyymm( season )
78
+
79
+ rows = nil
80
+ ## note: returns empty array if no match and NOT nil
81
+ rows = execute( <<-SQL )
82
+ SELECT #{self.columns.join(', ')}
83
+ FROM league_periods
84
+ INNER JOIN league_period_codes ON league_periods.id = league_period_codes.league_period_id
85
+ WHERE league_period_codes.code = '#{code}' AND
86
+ league_period_codes.start_yyyymm <= #{start_yyyymm} AND
87
+ league_period_codes.end_yyyymm >= #{end_yyyymm}
88
+ SQL
89
+
90
+ ## wrap results array into struct records
91
+ rows.map {|row| _build_league_period( row )}
92
+ end
93
+
94
+
95
+ def self.match_by_name( name, season: )
96
+ ## note: match must for now always include name
97
+ name = normalize( unaccent(name) )
98
+
99
+ season = Season( season )
100
+ start_yyyymm, end_yyyymm = _calc_yyyymm( season )
101
+
102
+ rows = nil
103
+ ## note: returns empty array if no match and NOT nil
104
+ rows = execute( <<-SQL )
105
+ SELECT #{self.columns.join(', ')}
106
+ FROM league_periods
107
+ INNER JOIN league_period_names ON league_periods.id = league_period_names.league_period_id
108
+ WHERE league_period_names.name = '#{name}' AND
109
+ league_period_names.start_yyyymm <= #{start_yyyymm} AND
110
+ league_period_names.end_yyyymm >= #{end_yyyymm}
111
+ SQL
112
+
113
+ ## wrap results array into struct records
114
+ rows.map {|row| _build_league_period( row )}
115
+ end
116
+
117
+
118
+ def self.match_by_name_or_code( q, season: )
119
+ name = normalize( unaccent(q) )
120
+ code = normalize( q )
121
+
122
+ season = Season( season )
123
+ start_yyyymm, end_yyyymm = _calc_yyyymm( season )
124
+
125
+ rows = nil
126
+ ## note: returns empty array if no match and NOT nil
127
+ rows = execute( <<-SQL )
128
+ SELECT #{self.columns.join(', ')}
129
+ FROM league_periods
130
+ INNER JOIN league_period_names ON league_periods.id = league_period_names.league_period_id
131
+ WHERE league_period_names.name = '#{name}' AND
132
+ league_period_names.start_yyyymm <= #{start_yyyymm} AND
133
+ league_period_names.end_yyyymm >= #{end_yyyymm}
134
+ UNION
135
+ SELECT #{self.columns.join(', ')}
136
+ FROM league_periods
137
+ INNER JOIN league_period_codes ON league_periods.id = league_period_codes.league_period_id
138
+ WHERE league_period_codes.code = '#{code}' AND
139
+ league_period_codes.start_yyyymm <= #{start_yyyymm} AND
140
+ league_period_codes.end_yyyymm >= #{end_yyyymm}
141
+ SQL
142
+
143
+ ## wrap results array into struct records
144
+ rows.map {|row| _build_league_period( row )}
145
+ end
146
+
147
+ end # class LeaguePeriod
148
+ end # module Metal
149
+ end # module CatalogDb
150
+
151
+
@@ -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 = 4
8
+ PATCH = 5
9
9
  VERSION = [MAJOR,MINOR,PATCH].join('.')
10
10
 
11
11
  def self.version
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-catalogs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.4
4
+ version: 1.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
@@ -108,6 +108,7 @@ files:
108
108
  - lib/sportdb/catalogs/event_info.rb
109
109
  - lib/sportdb/catalogs/ground.rb
110
110
  - lib/sportdb/catalogs/league.rb
111
+ - lib/sportdb/catalogs/league_period.rb
111
112
  - lib/sportdb/catalogs/national_team.rb
112
113
  - lib/sportdb/catalogs/player.rb
113
114
  - lib/sportdb/catalogs/version.rb