sportdb-structs 0.4.0 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +1 -1
- data/lib/sportdb/structs/country.rb +101 -5
- data/lib/sportdb/structs/league.rb +41 -10
- data/lib/sportdb/structs/match.rb +3 -0
- data/lib/sportdb/structs/version.rb +1 -1
- data/lib/sportdb/structs.rb +6 -3
- 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: 4603607b4234fbe74e0b57ed548a61a7d899041497d2e0e7f3104396b00e943a
|
4
|
+
data.tar.gz: 24945611ea43fca109b2a4b993ad6bf913daee4e034762d3797799d5a8a7bea5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 236bb3e8ac4e58e16b398e2fd9bdceabbd74e527a4aa1ef2af823976f31ef7b63f7342b640829218a2c9c08effd060675db67c4ec24d17497cee8071db4df0db
|
7
|
+
data.tar.gz: 7bdc16e2b06599fad689166a06bcd6b9aa4ef9ba4ddd0bb6c47a0d6aa68f6b20d9e2184ba0f211d9d9d455da6a7832ec14e9b5455aafe0e3c2c2e0c43f14dd5c
|
data/CHANGELOG.md
CHANGED
@@ -11,7 +11,7 @@ class City
|
|
11
11
|
attr_reader :key, :name, :country
|
12
12
|
attr_accessor :alt_names
|
13
13
|
|
14
|
-
def initialize( key: nil,
|
14
|
+
def initialize( key: nil,
|
15
15
|
name:, country: )
|
16
16
|
## note: auto-generate key "on-the-fly" if missing for now - why? why not?
|
17
17
|
## note: quick hack - auto-generate key, that is, remove all non-ascii chars and downcase
|
@@ -23,6 +23,7 @@ class City
|
|
23
23
|
end # class City
|
24
24
|
|
25
25
|
|
26
|
+
|
26
27
|
class Country
|
27
28
|
|
28
29
|
## note: is read-only/immutable for now - why? why not?
|
@@ -33,9 +34,9 @@ class Country
|
|
33
34
|
def initialize( key: nil, name:, code:, tags: [] )
|
34
35
|
## note: auto-generate key "on-the-fly" if missing for now - why? why not?
|
35
36
|
## note: quick hack - auto-generate key, that is, remove all non-ascii chars and downcase
|
36
|
-
@key = begin
|
37
|
+
@key = begin
|
37
38
|
if key
|
38
|
-
key
|
39
|
+
key
|
39
40
|
elsif code
|
40
41
|
code.downcase
|
41
42
|
else
|
@@ -47,14 +48,109 @@ class Country
|
|
47
48
|
@tags = tags
|
48
49
|
end
|
49
50
|
|
50
|
-
|
51
|
+
|
52
|
+
#############################
|
53
|
+
### virtual helpers
|
54
|
+
## 1) codes (returns uniq array of all codes in lowercase
|
55
|
+
## incl. key, code and alt_codes in alt_names)
|
56
|
+
## 2) names (returns uniq array of all names - with language tags stripped)
|
57
|
+
##
|
58
|
+
## 3a) adjective/adj - might be nil??
|
59
|
+
## b) adjectives/adjs
|
60
|
+
|
61
|
+
## note - alt_names - returns all-in-one alt names (& codes)
|
62
|
+
|
63
|
+
## note: split names into names AND codes
|
64
|
+
## 1) key plus all lower case names are codes
|
65
|
+
## 2) all upper case names are names AND codes
|
66
|
+
## 3) all other names are names
|
67
|
+
|
68
|
+
## only allow asci a to z in code & name for now - why? why not?
|
69
|
+
## e.g. USA, etc.
|
70
|
+
IS_CODE_N_NAME_RE = %r{^
|
71
|
+
[A-Z]+
|
72
|
+
$}x
|
73
|
+
## must be all lowercase (unicode letters allowed for now - why? why not?
|
74
|
+
## e.g. nirl, a, ö, etc.
|
75
|
+
IS_CODE_RE = %r{^
|
76
|
+
[\p{Ll}]+
|
77
|
+
$}x
|
78
|
+
|
79
|
+
def codes
|
80
|
+
## note - "auto-magically" downcase code (and code'n'name matches)!!!
|
81
|
+
codes = [@key, @code.downcase]
|
82
|
+
alt_names.each do |name|
|
83
|
+
if IS_CODE_N_NAME_RE.match?( name )
|
84
|
+
codes << name.downcase
|
85
|
+
elsif IS_CODE_RE.match?( name )
|
86
|
+
codes << name
|
87
|
+
else ## assume name
|
88
|
+
## do nothing - skip/ignore
|
89
|
+
end
|
90
|
+
end
|
91
|
+
codes.uniq
|
92
|
+
end
|
93
|
+
|
94
|
+
|
95
|
+
include SportDb::NameHelper # pulls-in strip_lang
|
96
|
+
|
97
|
+
def names
|
98
|
+
names = [@name]
|
99
|
+
alt_names.each do |name|
|
100
|
+
if IS_CODE_N_NAME_RE.match?( name )
|
101
|
+
names << name
|
102
|
+
elsif IS_CODE_RE.match?( name )
|
103
|
+
## do nothing - skip/ignore
|
104
|
+
else ## assume name
|
105
|
+
names << strip_lang( name )
|
106
|
+
end
|
107
|
+
end
|
108
|
+
names.uniq
|
109
|
+
end
|
110
|
+
|
111
|
+
## country adjectives - quick hack for now inline here
|
112
|
+
##
|
113
|
+
## todo - add language marker - why? why not`
|
114
|
+
## e.g. Österr. => Österr. [de]
|
115
|
+
## Deutsche` => Deutsche [de]
|
116
|
+
##
|
117
|
+
##
|
118
|
+
## todo/fix - add more - see
|
119
|
+
## https://en.wikipedia.org/wiki/List_of_adjectival_and_demonymic_forms_for_countries_and_nations
|
120
|
+
ADJ = {
|
121
|
+
'at' => ['Österr.', 'Austrian'],
|
122
|
+
'de' => ['Deutsche', 'German'],
|
123
|
+
'eng' => ['English'],
|
124
|
+
'sco' => ['Scottish'],
|
125
|
+
'wal' => ['Welsh'],
|
126
|
+
'nir' => ['Northern Irish'],
|
127
|
+
'ie' => ['Irish'],
|
128
|
+
|
129
|
+
'it' => ['Italian'],
|
130
|
+
'sm' => ['San Marinese'],
|
131
|
+
'fr' => ['French'],
|
132
|
+
'hu' => ['Hungarian'],
|
133
|
+
'gr' => ['Greek'],
|
134
|
+
'pt' => ['Portuguese'],
|
135
|
+
'ch' => ['Swiss'],
|
136
|
+
'tr' => ['Turkish'],
|
137
|
+
}
|
138
|
+
|
139
|
+
## note - adjective might be nil!!!
|
140
|
+
def adjective() adjectives[0]; end
|
141
|
+
def adjectives() ADJ[@key] || []; end
|
142
|
+
|
143
|
+
alias_method :adj, :adjective
|
144
|
+
alias_method :adjs, :adjectives
|
145
|
+
|
146
|
+
def pretty_print( printer )
|
51
147
|
buf = String.new
|
52
148
|
buf << "<Country: #{@key} - #{@name} (#{@code})"
|
53
149
|
buf << "|#{@alt_names.join('|')}" if @alt_names && !@alt_names.empty?
|
54
150
|
buf << ", #{@tags.join('|')})" if @tags && !@tags.empty?
|
55
151
|
buf << ">"
|
56
152
|
|
57
|
-
printer.text( buf )
|
153
|
+
printer.text( buf )
|
58
154
|
end
|
59
155
|
end # class Country
|
60
156
|
|
@@ -2,9 +2,27 @@
|
|
2
2
|
module Sports
|
3
3
|
|
4
4
|
|
5
|
+
class LeaguePeriod
|
6
|
+
attr_reader :key, :name, :qname, :slug,
|
7
|
+
:prev_name, :start_season, :end_season
|
8
|
+
def initialize( key:, name:, qname:, slug:,
|
9
|
+
prev_name: nil,
|
10
|
+
start_season: nil, end_season: nil )
|
11
|
+
@key = key
|
12
|
+
@name = name
|
13
|
+
@qname = qname
|
14
|
+
@slug = slug
|
15
|
+
@prev_name = prev_name
|
16
|
+
@start_season = start_season
|
17
|
+
@end_season = end_season
|
18
|
+
end
|
19
|
+
end # class LeaguePeriod
|
20
|
+
|
21
|
+
|
5
22
|
class League
|
6
23
|
attr_reader :key, :name, :country, :intl
|
7
24
|
attr_accessor :alt_names
|
25
|
+
attr_accessor :periods
|
8
26
|
|
9
27
|
|
10
28
|
def initialize( key:, name:, alt_names: [],
|
@@ -12,12 +30,15 @@ class League
|
|
12
30
|
@key = key
|
13
31
|
@name = name
|
14
32
|
@alt_names = alt_names
|
15
|
-
|
33
|
+
|
16
34
|
@country = country
|
17
35
|
@intl = intl
|
18
36
|
@clubs = clubs
|
37
|
+
|
38
|
+
@periods = [] ## change/rename to history - why? why not?
|
19
39
|
end
|
20
40
|
|
41
|
+
|
21
42
|
def intl?() @intl == true; end
|
22
43
|
def national?() @intl == false; end
|
23
44
|
alias_method :domestic?, :national?
|
@@ -27,30 +48,40 @@ class League
|
|
27
48
|
alias_method :club?, :clubs?
|
28
49
|
alias_method :national_team?, :national_teams?
|
29
50
|
|
30
|
-
=begin
|
51
|
+
=begin
|
31
52
|
@alt_names=[],
|
32
53
|
@clubs=true,
|
33
54
|
@country=<Country: at - Austria (AUT)|Österreich [de], fifa|uefa)>,
|
34
55
|
@intl=false,
|
35
56
|
@key="at.1",
|
36
|
-
@name="Bundesliga">,
|
57
|
+
@name="Bundesliga">,
|
37
58
|
=end
|
38
59
|
|
39
|
-
def pretty_print( printer )
|
60
|
+
def pretty_print( printer )
|
40
61
|
buf = String.new
|
41
62
|
buf << "<League"
|
42
63
|
buf << " INTL" if @intl
|
43
|
-
buf << if @clubs
|
44
|
-
" CLUBS"
|
45
|
-
else
|
64
|
+
buf << if @clubs
|
65
|
+
" CLUBS"
|
66
|
+
else
|
46
67
|
" NATIONAL TEAMS"
|
47
|
-
end
|
68
|
+
end
|
48
69
|
buf << ": #{@key} - #{@name}"
|
49
|
-
|
70
|
+
|
71
|
+
if @alt_names && !@alt_names.empty?
|
72
|
+
buf << "|"
|
73
|
+
buf << @alt_names.join('|')
|
74
|
+
end
|
75
|
+
|
50
76
|
buf << ", #{@country.name} (#{@country.code})" if @country
|
77
|
+
|
78
|
+
if @periods && !@periods.empty?
|
79
|
+
buf << ", "
|
80
|
+
buf << @periods.map{|period| period.key }.uniq.join('|')
|
81
|
+
end
|
51
82
|
buf << ">"
|
52
83
|
|
53
|
-
printer.text( buf )
|
84
|
+
printer.text( buf )
|
54
85
|
end
|
55
86
|
|
56
87
|
|
@@ -212,7 +212,10 @@ def as_json
|
|
212
212
|
data[:score][:et] = [@score1et, @score2et] if @score1et && @score2et
|
213
213
|
data[:score][:p] = [@score1p, @score2p] if @score1p && @score2p
|
214
214
|
|
215
|
+
data[:status] = @status if @status
|
216
|
+
|
215
217
|
data[:group] = @group if @group
|
218
|
+
data[:stage] = @stage if @stage
|
216
219
|
|
217
220
|
=begin
|
218
221
|
"round": "Spieltag 1",
|
data/lib/sportdb/structs.rb
CHANGED
@@ -8,6 +8,9 @@ require 'score/formats'
|
|
8
8
|
# our own code
|
9
9
|
require_relative 'structs/version' # let version always go first
|
10
10
|
|
11
|
+
## shared support helpers/machinery
|
12
|
+
require_relative 'structs/name_helper'
|
13
|
+
|
11
14
|
require_relative 'structs/country'
|
12
15
|
require_relative 'structs/league'
|
13
16
|
require_relative 'structs/team'
|
@@ -24,9 +27,6 @@ require_relative 'structs/team_usage'
|
|
24
27
|
require_relative 'structs/event_info'
|
25
28
|
|
26
29
|
|
27
|
-
## shared support helpers/machinery
|
28
|
-
require_relative 'structs/name_helper'
|
29
|
-
|
30
30
|
|
31
31
|
##
|
32
32
|
## todo/fix - move "inline" player to structs/player file !!!!
|
@@ -76,7 +76,10 @@ module SportDb
|
|
76
76
|
## add "old" convenience aliases for structs - why? why not?
|
77
77
|
## todo/check: just use include Sports !!!!
|
78
78
|
Country = ::Sports::Country
|
79
|
+
City = ::Sports::City
|
80
|
+
|
79
81
|
League = ::Sports::League
|
82
|
+
LeaguePeriod = ::Sports::LeaguePeriod
|
80
83
|
Group = ::Sports::Group
|
81
84
|
Round = ::Sports::Round
|
82
85
|
Match = ::Sports::Match
|
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.4.
|
4
|
+
version: 0.4.2
|
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-
|
11
|
+
date: 2024-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: alphabets
|