sportdb-structs 0.5.0 → 0.5.1
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 +1 -2
- data/lib/sportdb/structs/league.rb +88 -0
- data/lib/sportdb/structs/match.rb +32 -13
- data/lib/sportdb/structs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f93a521b7edcab10afea6cb26770b1924b23cb0c8a1b1d25080c57132b0e21b
|
4
|
+
data.tar.gz: f0099bb428f29a92f1419096d0f693671d035718ec816dbca4a9d4ca5376e497
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ee368ed13cfb5c2ea432404eb7a7171bbfb82a3d543773ff0ec66a5840f91301c719e9a373cb49826080e9c811f391566d2d5608fe4f8cb56d6a4f601babccc
|
7
|
+
data.tar.gz: d81f2090d34dc149a6667a09a89016d1c89a9b3f34b2876ce2b2f973843756102b1dfcfb275f0e0d0f4540dace8b0f6f5fe2b474764e5884eac9b0a3fb7ae719
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,9 @@ module Sports
|
|
5
5
|
class LeaguePeriod
|
6
6
|
attr_reader :key, :name, :qname, :slug,
|
7
7
|
:prev_name, :start_season, :end_season
|
8
|
+
|
9
|
+
attr_accessor :alt_names
|
10
|
+
|
8
11
|
def initialize( key:, name:, qname:, slug:,
|
9
12
|
prev_name: nil,
|
10
13
|
start_season: nil, end_season: nil )
|
@@ -15,6 +18,91 @@ class LeaguePeriod
|
|
15
18
|
@prev_name = prev_name
|
16
19
|
@start_season = start_season
|
17
20
|
@end_season = end_season
|
21
|
+
|
22
|
+
@alt_names = []
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
####
|
27
|
+
## todo/fix - share code for names and codes with League and LeaguePeriod!!!
|
28
|
+
## for now cut-n-paste copy
|
29
|
+
|
30
|
+
#############################
|
31
|
+
### virtual helpers
|
32
|
+
## 1) codes (returns uniq array of all codes in lowercase
|
33
|
+
## incl. key, code and alt_codes in alt_names)
|
34
|
+
## 2) names (returns uniq array of all names - with language tags stripped)
|
35
|
+
##
|
36
|
+
|
37
|
+
## note: split names into names AND codes
|
38
|
+
## 1) key plus all lower case names are codes
|
39
|
+
## 2) all upper case names are names AND codes
|
40
|
+
## 3) all other names are names
|
41
|
+
|
42
|
+
## only allow asci a to z (why? why not?)
|
43
|
+
## excludes Ö1 or such (what else?)
|
44
|
+
## allow space and dot - why? why not?
|
45
|
+
## e.g. HNL 1
|
46
|
+
## NB I or NB II etc.
|
47
|
+
IS_CODE_N_NAME_RE = %r{^
|
48
|
+
[\p{Lu}0-9. ]+
|
49
|
+
$}x
|
50
|
+
## add space (or /) - why? why not?
|
51
|
+
IS_CODE_RE = %r{^
|
52
|
+
[\p{Ll}0-9.]+
|
53
|
+
$}x
|
54
|
+
|
55
|
+
|
56
|
+
def codes
|
57
|
+
## change/rename to more_codes - why? why?
|
58
|
+
## get reference (tier/canonicial) codes via periods!!!!
|
59
|
+
|
60
|
+
## note - "auto-magically" downcase code (and code'n'name matches)!!
|
61
|
+
## note - do NOT include key as code for now!!!
|
62
|
+
##
|
63
|
+
## todo/check - auto-remove space from code - why? why not?
|
64
|
+
## e.g. NB I, NB II, HNL 1 => NBI, NBII, HBNL1, etc -
|
65
|
+
codes = []
|
66
|
+
alt_names.each do |name|
|
67
|
+
if IS_CODE_N_NAME_RE.match?( name )
|
68
|
+
codes << name.downcase
|
69
|
+
elsif IS_CODE_RE.match?( name )
|
70
|
+
codes << name
|
71
|
+
else ## assume name
|
72
|
+
## do nothing - skip/ignore
|
73
|
+
end
|
74
|
+
end
|
75
|
+
codes.uniq
|
76
|
+
end
|
77
|
+
|
78
|
+
|
79
|
+
include SportDb::NameHelper # pulls-in strip_lang
|
80
|
+
|
81
|
+
def names
|
82
|
+
names = [@name]
|
83
|
+
alt_names.each do |name|
|
84
|
+
if IS_CODE_N_NAME_RE.match?( name )
|
85
|
+
names << name
|
86
|
+
elsif IS_CODE_RE.match?( name )
|
87
|
+
## do nothing - skip/ignore
|
88
|
+
else ## assume name
|
89
|
+
names << strip_lang( name )
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
## report duplicate names - why? why not
|
94
|
+
## check for duplicates - simple check for now - fix/improve
|
95
|
+
## todo/fix: (auto)remove duplicates - why? why not?
|
96
|
+
count = names.size
|
97
|
+
count_uniq = names.uniq.size
|
98
|
+
if count != count_uniq
|
99
|
+
puts "** !!! ERROR !!! - #{count-count_uniq} duplicate name(s):"
|
100
|
+
pp names
|
101
|
+
pp self
|
102
|
+
exit 1
|
103
|
+
end
|
104
|
+
|
105
|
+
names.uniq
|
18
106
|
end
|
19
107
|
|
20
108
|
|
@@ -23,7 +23,8 @@ class Match
|
|
23
23
|
:country1, :country2, ## special case for champions league etc. - uses FIFA country code
|
24
24
|
:comments,
|
25
25
|
:league, ## (optinal) added as text for now (use struct?)
|
26
|
-
:ground ## (optional) add as text line for now (incl. city, timezone etc.)
|
26
|
+
:ground, ## (optional) add as text line for now (incl. city, timezone etc.)
|
27
|
+
:timezone ## (optional) as a string
|
27
28
|
|
28
29
|
attr_accessor :goals ## todo/fix: make goals like all other attribs!!
|
29
30
|
|
@@ -66,6 +67,7 @@ class Match
|
|
66
67
|
|
67
68
|
@league = kwargs[:league] if kwargs.has_key?( :league )
|
68
69
|
@ground = kwargs[:ground] if kwargs.has_key?( :ground )
|
70
|
+
@timezone = kwargs[:timezone] if kwargs.has_key?( :timezone )
|
69
71
|
|
70
72
|
|
71
73
|
if kwargs.has_key?( :score ) ## check all-in-one score struct for convenience!!!
|
@@ -214,23 +216,40 @@ def as_json
|
|
214
216
|
data['score']['et'] = [@score1et, @score2et] if @score1et && @score2et
|
215
217
|
data['score']['p'] = [@score1p, @score2p] if @score1p && @score2p
|
216
218
|
|
219
|
+
### check for goals
|
220
|
+
if @goals && @goals.size > 0
|
221
|
+
data['goals1'] = []
|
222
|
+
data['goals2'] = []
|
223
|
+
|
224
|
+
@goals.each do |goal|
|
225
|
+
node = {}
|
226
|
+
node['name'] = goal.player
|
227
|
+
node['minute'] = goal.minute
|
228
|
+
node['offset'] = goal.offset if goal.offset
|
229
|
+
node['owngoal'] = true if goal.owngoal
|
230
|
+
node['penalty'] = true if goal.penalty
|
231
|
+
|
232
|
+
if goal.team == 1
|
233
|
+
data['goals1'] << node
|
234
|
+
else ## assume 2
|
235
|
+
data['goals2'] << node
|
236
|
+
end
|
237
|
+
end # each goal
|
238
|
+
end
|
239
|
+
|
240
|
+
|
217
241
|
data['status'] = @status if @status
|
218
242
|
|
219
243
|
data['group'] = @group if @group
|
220
244
|
data['stage'] = @stage if @stage
|
221
245
|
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
1,
|
230
|
-
1
|
231
|
-
]
|
232
|
-
}
|
233
|
-
=end
|
246
|
+
if @ground
|
247
|
+
## note: might be array of string e.g. ['Wembley', 'London']
|
248
|
+
data['ground'] = {}
|
249
|
+
data['ground']['name'] = @ground
|
250
|
+
data['ground']['timezone'] = @timezone if @timezone
|
251
|
+
end
|
252
|
+
|
234
253
|
data
|
235
254
|
end
|
236
255
|
|
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.5.
|
4
|
+
version: 0.5.1
|
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: 2025-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cocos
|