sportdb-formats 1.1.6 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +2 -0
  3. data/Manifest.txt +4 -25
  4. data/Rakefile +1 -1
  5. data/lib/sportdb/formats/country/country_reader.rb +142 -142
  6. data/lib/sportdb/formats/datafile.rb +59 -59
  7. data/lib/sportdb/formats/event/event_reader.rb +184 -183
  8. data/lib/sportdb/formats/goals.rb +37 -1
  9. data/lib/sportdb/formats/ground/ground_reader.rb +289 -0
  10. data/lib/sportdb/formats/league/league_reader.rb +152 -168
  11. data/lib/sportdb/formats/lines_reader.rb +47 -0
  12. data/lib/sportdb/formats/match/match_parser.rb +102 -12
  13. data/lib/sportdb/formats/match/match_parser_auto_conf.rb +270 -202
  14. data/lib/sportdb/formats/outline_reader.rb +0 -1
  15. data/lib/sportdb/formats/package.rb +394 -374
  16. data/lib/sportdb/formats/search/sport.rb +357 -0
  17. data/lib/sportdb/formats/search/world.rb +139 -0
  18. data/lib/sportdb/formats/team/club_index_history.rb +134 -134
  19. data/lib/sportdb/formats/team/club_reader.rb +318 -350
  20. data/lib/sportdb/formats/team/club_reader_history.rb +203 -203
  21. data/lib/sportdb/formats/team/wiki_reader.rb +108 -108
  22. data/lib/sportdb/formats/version.rb +4 -7
  23. data/lib/sportdb/formats.rb +60 -27
  24. metadata +13 -35
  25. data/lib/sportdb/formats/country/country_index.rb +0 -192
  26. data/lib/sportdb/formats/event/event_index.rb +0 -141
  27. data/lib/sportdb/formats/league/league_index.rb +0 -178
  28. data/lib/sportdb/formats/team/club_index.rb +0 -338
  29. data/lib/sportdb/formats/team/national_team_index.rb +0 -114
  30. data/lib/sportdb/formats/team/team_index.rb +0 -43
  31. data/test/helper.rb +0 -132
  32. data/test/test_club_index.rb +0 -183
  33. data/test/test_club_index_history.rb +0 -107
  34. data/test/test_club_reader.rb +0 -201
  35. data/test/test_club_reader_history.rb +0 -212
  36. data/test/test_club_reader_props.rb +0 -54
  37. data/test/test_country_index.rb +0 -63
  38. data/test/test_country_reader.rb +0 -89
  39. data/test/test_datafile.rb +0 -30
  40. data/test/test_datafile_package.rb +0 -46
  41. data/test/test_goals.rb +0 -113
  42. data/test/test_league_index.rb +0 -157
  43. data/test/test_league_outline_reader.rb +0 -55
  44. data/test/test_league_reader.rb +0 -72
  45. data/test/test_outline_reader.rb +0 -31
  46. data/test/test_package.rb +0 -78
  47. data/test/test_package_match.rb +0 -102
  48. data/test/test_regex.rb +0 -67
  49. data/test/test_wiki_reader.rb +0 -77
@@ -9,15 +9,49 @@ require 'zip' ## todo/check: if zip is alreay included in a required module
9
9
 
10
10
  ###
11
11
  # our own code
12
- require 'sportdb/formats/version' # let version always go first
12
+ require_relative 'formats/version' # let version always go first
13
+
14
+ require_relative 'formats/outline_reader'
15
+ require_relative 'formats/datafile'
16
+ require_relative 'formats/datafile_package'
17
+ require_relative 'formats/package'
18
+
19
+
20
+ require_relative 'formats/parser_helper'
21
+
22
+ require_relative 'formats/lines_reader'
23
+
24
+
25
+ ###
26
+ # define search services apis (move to its own gem later - why? why not?)
27
+
28
+ module SportDb
29
+ module Import
30
+
31
+ class Configuration
32
+ ## note: add more configs (open class), see sportdb-structs for original config!!!
33
+
34
+ ## add
35
+ def world() @world ||= WorldSearch.new( countries: DummyCountrySearch.new ); end
36
+ def world=(world) @world = world; end
37
+
38
+ ## tood/fix - add/move catalog here from sportdb-catalogs!!!
39
+ ## def catalog() @catalog ||= Catalog.new; end
40
+ ## def catalog(catalog) @catalog = catalog; end
41
+ end # class Configuration
42
+
43
+ ## e.g. use config.catalog -- keep Import.catalog as a shortcut (for "read-only" access)
44
+ ## def self.catalog() config.catalog; end
45
+ def self.world() config.world; end
46
+ end # module Import
47
+ end # module SportDb
48
+
49
+ require_relative 'formats/search/world'
50
+ require_relative 'formats/search/sport'
51
+
13
52
 
14
- require 'sportdb/formats/outline_reader'
15
- require 'sportdb/formats/datafile'
16
- require 'sportdb/formats/datafile_package'
17
- require 'sportdb/formats/package'
18
53
 
19
54
 
20
- require 'sportdb/formats/parser_helper'
21
55
 
22
56
 
23
57
  module SportDb
@@ -39,7 +73,11 @@ module SportDb
39
73
  Standings = ::Sports::Standings
40
74
  TeamUsage = ::Sports::TeamUsage
41
75
 
76
+ Ground = ::Sports::Ground
77
+
78
+ Player = ::Sports::Player
42
79
 
80
+
43
81
  class Team
44
82
  ## add convenience lookup helper / method for name by season for now
45
83
  ## use clubs history - for now kept separate from struct - why? why not?
@@ -53,20 +91,19 @@ module SportDb
53
91
  end # module SportDb
54
92
 
55
93
 
56
- require 'sportdb/formats/goals'
94
+ require_relative 'formats/goals'
57
95
 
58
96
 
59
97
 
60
- require 'sportdb/formats/match/mapper'
61
- require 'sportdb/formats/match/mapper_teams'
62
- require 'sportdb/formats/match/match_parser'
63
- require 'sportdb/formats/match/match_parser_auto_conf'
64
- require 'sportdb/formats/match/conf_parser'
98
+ require_relative 'formats/match/mapper'
99
+ require_relative 'formats/match/mapper_teams'
100
+ require_relative 'formats/match/match_parser'
101
+ require_relative 'formats/match/match_parser_auto_conf'
102
+ require_relative 'formats/match/conf_parser'
65
103
 
66
104
 
67
105
 
68
- require 'sportdb/formats/country/country_reader'
69
- require 'sportdb/formats/country/country_index'
106
+ require_relative 'formats/country/country_reader'
70
107
 
71
108
 
72
109
  ## add convenience helper
@@ -80,9 +117,8 @@ end # module Import
80
117
  end # module SportDb
81
118
 
82
119
 
83
- require 'sportdb/formats/league/league_reader'
84
- require 'sportdb/formats/league/league_index'
85
- require 'sportdb/formats/league/league_outline_reader'
120
+ require_relative 'formats/league/league_reader'
121
+ require_relative 'formats/league/league_outline_reader'
86
122
 
87
123
  ##
88
124
  ## add convenience helper / short-cuts
@@ -96,15 +132,12 @@ end # module Import
96
132
  end # module SportDb
97
133
 
98
134
 
99
- require 'sportdb/formats/team/club_reader'
100
- require 'sportdb/formats/team/club_reader_props'
101
- require 'sportdb/formats/team/club_index'
102
- require 'sportdb/formats/team/wiki_reader'
103
- require 'sportdb/formats/team/national_team_index'
104
- require 'sportdb/formats/team/team_index'
135
+ require_relative 'formats/team/club_reader'
136
+ require_relative 'formats/team/club_reader_props'
137
+ require_relative 'formats/team/wiki_reader'
105
138
 
106
- require 'sportdb/formats/team/club_reader_history'
107
- require 'sportdb/formats/team/club_index_history'
139
+ require_relative 'formats/team/club_reader_history'
140
+ require_relative 'formats/team/club_index_history'
108
141
 
109
142
 
110
143
  ###
@@ -125,8 +158,7 @@ end # module Import
125
158
  end # module SportDb
126
159
 
127
160
 
128
- require 'sportdb/formats/event/event_reader'
129
- require 'sportdb/formats/event/event_index'
161
+ require_relative 'formats/event/event_reader'
130
162
 
131
163
  ## add convenience helper
132
164
  module SportDb
@@ -140,6 +172,7 @@ end # module SportDb
140
172
 
141
173
 
142
174
 
175
+ require_relative 'formats/ground/ground_reader'
143
176
 
144
177
 
145
178
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sportdb-formats
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.6
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-06 00:00:00.000000000 Z
11
+ date: 2024-06-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sportdb-structs
@@ -64,16 +64,16 @@ dependencies:
64
64
  requirements:
65
65
  - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '3.22'
67
+ version: '4.1'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '3.22'
74
+ version: '4.1'
75
75
  description: sportdb-formats - sport.db format and text utilities
76
- email: opensport@googlegroups.com
76
+ email: gerald.bauer@gmail.com
77
77
  executables: []
78
78
  extensions: []
79
79
  extra_rdoc_files:
@@ -86,16 +86,15 @@ files:
86
86
  - README.md
87
87
  - Rakefile
88
88
  - lib/sportdb/formats.rb
89
- - lib/sportdb/formats/country/country_index.rb
90
89
  - lib/sportdb/formats/country/country_reader.rb
91
90
  - lib/sportdb/formats/datafile.rb
92
91
  - lib/sportdb/formats/datafile_package.rb
93
- - lib/sportdb/formats/event/event_index.rb
94
92
  - lib/sportdb/formats/event/event_reader.rb
95
93
  - lib/sportdb/formats/goals.rb
96
- - lib/sportdb/formats/league/league_index.rb
94
+ - lib/sportdb/formats/ground/ground_reader.rb
97
95
  - lib/sportdb/formats/league/league_outline_reader.rb
98
96
  - lib/sportdb/formats/league/league_reader.rb
97
+ - lib/sportdb/formats/lines_reader.rb
99
98
  - lib/sportdb/formats/match/conf_parser.rb
100
99
  - lib/sportdb/formats/match/mapper.rb
101
100
  - lib/sportdb/formats/match/mapper_teams.rb
@@ -104,39 +103,19 @@ files:
104
103
  - lib/sportdb/formats/outline_reader.rb
105
104
  - lib/sportdb/formats/package.rb
106
105
  - lib/sportdb/formats/parser_helper.rb
107
- - lib/sportdb/formats/team/club_index.rb
106
+ - lib/sportdb/formats/search/sport.rb
107
+ - lib/sportdb/formats/search/world.rb
108
108
  - lib/sportdb/formats/team/club_index_history.rb
109
109
  - lib/sportdb/formats/team/club_reader.rb
110
110
  - lib/sportdb/formats/team/club_reader_history.rb
111
111
  - lib/sportdb/formats/team/club_reader_props.rb
112
- - lib/sportdb/formats/team/national_team_index.rb
113
- - lib/sportdb/formats/team/team_index.rb
114
112
  - lib/sportdb/formats/team/wiki_reader.rb
115
113
  - lib/sportdb/formats/version.rb
116
- - test/helper.rb
117
- - test/test_club_index.rb
118
- - test/test_club_index_history.rb
119
- - test/test_club_reader.rb
120
- - test/test_club_reader_history.rb
121
- - test/test_club_reader_props.rb
122
- - test/test_country_index.rb
123
- - test/test_country_reader.rb
124
- - test/test_datafile.rb
125
- - test/test_datafile_package.rb
126
- - test/test_goals.rb
127
- - test/test_league_index.rb
128
- - test/test_league_outline_reader.rb
129
- - test/test_league_reader.rb
130
- - test/test_outline_reader.rb
131
- - test/test_package.rb
132
- - test/test_package_match.rb
133
- - test/test_regex.rb
134
- - test/test_wiki_reader.rb
135
114
  homepage: https://github.com/sportdb/sport.db
136
115
  licenses:
137
116
  - Public Domain
138
117
  metadata: {}
139
- post_install_message:
118
+ post_install_message:
140
119
  rdoc_options:
141
120
  - "--main"
142
121
  - README.md
@@ -153,9 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
153
132
  - !ruby/object:Gem::Version
154
133
  version: '0'
155
134
  requirements: []
156
- rubyforge_project:
157
- rubygems_version: 2.5.2
158
- signing_key:
135
+ rubygems_version: 3.4.10
136
+ signing_key:
159
137
  specification_version: 4
160
138
  summary: sportdb-formats - sport.db format and text utilities
161
139
  test_files: []
@@ -1,192 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
- module Import
5
-
6
- ## built-in countries for (quick starter) auto-add
7
- class CountryIndex
8
-
9
- attr_reader :countries ## all country records
10
-
11
- def initialize( recs )
12
- @countries = []
13
- @countries_by_code = {}
14
- @countries_by_name = {}
15
-
16
- add( recs )
17
- end
18
-
19
-
20
- ## helpers from country - use a helper module for includes (share with clubs etc.) - why? why not?
21
- include NameHelper
22
- ## incl. strip_year( name )
23
- ## has_year?( name)
24
- ## strip_lang( name )
25
- ## normalize( name )
26
-
27
-
28
- def add( recs )
29
- ###########################################
30
- ## auto-fill countries
31
- ## pp recs
32
- recs.each do |rec|
33
- ## rec e.g. { key:'af', code:'AFG', name:'Afghanistan'}
34
-
35
- @countries << rec
36
-
37
- ## add codes lookups - key, code, ...
38
- if @countries_by_code[ rec.key ]
39
- puts "** !! ERROR !! country code (key) >#{rec.key}< already exits!!"
40
- exit 1
41
- else
42
- @countries_by_code[ rec.key ] = rec
43
- end
44
-
45
- ## add code (only) if different from key
46
- if rec.key != rec.code.downcase
47
- if @countries_by_code[ rec.code.downcase ]
48
- puts "** !! ERROR !! country code >#{rec.code.downcase}< already exits!!"
49
- exit 1
50
- else
51
- @countries_by_code[ rec.code.downcase ] = rec
52
- end
53
- end
54
-
55
-
56
- ## add all names (canonical name + alt names
57
- names = [rec.name] + rec.alt_names
58
- more_names = []
59
- ## check "hand-typed" names for year (auto-add)
60
- ## check for year(s) e.g. (1887-1911), (-2013),
61
- ## (1946-2001,2013-) etc.
62
- names.each do |name|
63
- if has_year?( name )
64
- more_names << strip_year( name )
65
- end
66
- end
67
-
68
- names += more_names
69
- ## check for duplicates - simple check for now - fix/improve
70
- ## todo/fix: (auto)remove duplicates - why? why not?
71
- count = names.size
72
- count_uniq = names.uniq.size
73
- if count != count_uniq
74
- puts "** !!! ERROR !!! - #{count-count_uniq} duplicate name(s):"
75
- pp names
76
- pp rec
77
- exit 1
78
- end
79
-
80
- names.each_with_index do |name,i|
81
- ## check lang codes e.g. [en], [fr], etc.
82
- ## todo/check/fix: move strip_lang up in the chain - check for duplicates (e.g. only lang code marker different etc.) - why? why not?
83
- name = strip_lang( name )
84
- norm = normalize( name )
85
- old_rec = @countries_by_name[ norm ]
86
- if old_rec
87
- ## check if country name already is included or is new country rec
88
- msg = "** !!! ERROR !!! - name conflict/duplicate - >#{name}< will overwrite >#{old_rec.name}< with >#{rec.name}<"
89
- puts msg
90
- exit 1
91
- else
92
- @countries_by_name[ norm ] = rec
93
- end
94
- end
95
-
96
- end ## each record
97
- end # method initialize
98
-
99
-
100
-
101
- ## fix/todo: add find_by (alias for find_by_name/find_by_code)
102
- def find_by_code( code )
103
- code = code.to_s.downcase ## allow symbols (and always downcase e.g. AUT to aut etc.)
104
- @countries_by_code[ code ]
105
- end
106
-
107
- def find_by_name( name )
108
- name = normalize( name.to_s ) ## allow symbols too (e.g. use to.s first)
109
- @countries_by_name[ name ]
110
- end
111
-
112
- def find( key )
113
- country = find_by_code( key )
114
- country = find_by_name( key ) if country.nil? ## try lookup / find by (normalized) name
115
- country
116
- end
117
- alias_method :[], :find
118
-
119
-
120
- ###
121
- ## split/parse country line
122
- ##
123
- ## split on bullet e.g.
124
- ## split into name and code with regex - make code optional
125
- ##
126
- ## Examples:
127
- ## Österreich • Austria (at)
128
- ## Österreich • Austria
129
- ## Austria
130
- ## Deutschland (de) • Germany
131
- ##
132
- ## todo/check: support more formats - why? why not?
133
- ## e.g. Austria, AUT (e.g. with comma - why? why not?)
134
- def parse( line )
135
- values = line.split( '•' ) ## use/support multi-lingual separator
136
- country = nil
137
- values.each do |value|
138
- value = value.strip
139
- ## check for trailing country code e.g. (at), (eng), etc.
140
- if value =~ /[ ]+\((?<code>[a-z]{1,4})\)$/ ## e.g. Austria (at)
141
- code = $~[:code]
142
- name = value[0...(value.size-code.size-2)].strip ## note: add -2 for brackets
143
- candidates = [ find_by_code( code ), find_by_name( name ) ]
144
- if candidates[0].nil?
145
- puts "** !!! ERROR !!! country - unknown code >#{code}< in line: #{line}"
146
- pp line
147
- exit 1
148
- end
149
- if candidates[1].nil?
150
- puts "** !!! ERROR !!! country - unknown name >#{code}< in line: #{line}"
151
- pp line
152
- exit 1
153
- end
154
- if candidates[0] != candidates[1]
155
- puts "** !!! ERROR !!! country - name and code do NOT match the same country:"
156
- pp line
157
- pp candidates
158
- exit 1
159
- end
160
- if country && country != candidates[0]
161
- puts "** !!! ERROR !!! country - names do NOT match the same country:"
162
- pp line
163
- pp country
164
- pp candidates
165
- exit 1
166
- end
167
- country = candidates[0]
168
- else
169
- ## just assume value is name or code
170
- candidate = find( value )
171
- if candidate.nil?
172
- puts "** !!! ERROR !!! country - unknown name or code >#{value}< in line: #{line}"
173
- pp line
174
- exit 1
175
- end
176
- if country && country != candidate
177
- puts "** !!! ERROR !!! country - names do NOT match the same country:"
178
- pp line
179
- pp country
180
- pp candidate
181
- exit 1
182
- end
183
- country = candidate
184
- end
185
- end
186
- country
187
- end # method parse
188
- end # class CountryIndex
189
-
190
-
191
- end # module Import
192
- end # module SportDb
@@ -1,141 +0,0 @@
1
- module SportDb
2
- module Import
3
-
4
-
5
-
6
- class EventIndex
7
-
8
- def self.build( path )
9
- pack = Package.new( path ) ## lets us use direcotry or zip archive
10
-
11
- recs = []
12
- pack.each_seasons do |entry|
13
- recs += EventInfoReader.parse( entry.read )
14
- end
15
- recs
16
-
17
- index = new
18
- index.add( recs )
19
- index
20
- end
21
-
22
-
23
-
24
- attr_reader :events
25
- def initialize
26
- @events = []
27
- @leagues = {}
28
- end
29
-
30
- def add( recs )
31
- @events += recs ## add to "linear" records
32
-
33
- recs.each do |rec|
34
- league = rec.league
35
- season = rec.season
36
-
37
- seasons = @leagues[ league.key ] ||= {}
38
- seasons[season.key] = rec
39
- end
40
- ## build search index by leagues (and season)
41
- end
42
-
43
- def find_by( league:, season: )
44
- league_key = league.is_a?( String ) ? league : league.key
45
- season_key = season.is_a?( String ) ? season : season.key
46
-
47
- seasons = @leagues[ league_key ]
48
- if seasons
49
- seasons[ season_key ]
50
- else
51
- nil
52
- end
53
- end # method find_by
54
- end ## class EventIndex
55
-
56
-
57
-
58
- class SeasonIndex
59
- def initialize( *args )
60
- @leagues = {} ## use a league hash by years for now; change later
61
-
62
- if args.size == 1 && args[0].is_a?( EventIndex )
63
- ## convenience setup/hookup
64
- ## (auto-)add all events from event index
65
- add( args[0].events )
66
- else
67
- pp args
68
- raise ArgumentError.new( 'unsupported arguments' )
69
- end
70
- end
71
-
72
- def add( recs )
73
- ## use a lookup index by year for now
74
- ## todo - find something better/more generic for searching/matching date periods!!!
75
- recs.each do |rec|
76
- league = rec.league
77
- season = rec.season
78
-
79
- years = @leagues[ league.key ] ||= {}
80
- if season.year?
81
- years[season.start_year] ||= []
82
- years[season.start_year] << rec
83
- else
84
- years[season.start_year] ||= []
85
- years[season.end_year] ||= []
86
- years[season.start_year] << rec
87
- years[season.end_year] << rec
88
- end
89
- end
90
- end # method add
91
-
92
- def find_by( date:, league: )
93
- date = Date.strptime( date, '%Y-%m-%d' ) if date.is_a?( String )
94
- league_key = league.is_a?( String ) ? league : league.key
95
-
96
- years = @leagues[ league_key ]
97
- if years
98
- year = years[ date.year ]
99
- if year
100
- season_key = nil
101
- year.each do |event|
102
- ## todo/check: rename/use between? instead of include? - why? why not?
103
- if event.include?( date )
104
- season_key = event.season.key
105
- break
106
- end
107
- end
108
- if season_key.nil?
109
- puts "!! WARN: date >#{date}< out-of-seasons for year #{date.year} in league #{league_key}:"
110
- year.each do |event|
111
- puts " #{event.season.key} | #{event.start_date} - #{event.end_date}"
112
- end
113
- ## retry again and pick season with "overflow" at the end (date is great end_date)
114
- year.each do |event|
115
- if date > event.end_date
116
- diff_in_days = date.to_date.jd - event.end_date.to_date.jd
117
- puts " +#{diff_in_days} days - adding overflow to #{event.season.key} ending on #{event.end_date} ++ #{date}"
118
- season_key = event.season.key
119
- break
120
- end
121
- end
122
- ## exit now for sure - if still empty!!!!
123
- if season_key.nil?
124
- puts "!! ERROR: CANNOT auto-fix / (auto-)append date at the end of an event; check season setup - sorry"
125
- exit 1
126
- end
127
- end
128
- season_key
129
- else
130
- nil ## no year defined / found for league
131
- end
132
- else
133
- nil ## no league defined / found
134
- end
135
- end # method find
136
-
137
- end # class SeasonIndex
138
-
139
-
140
- end # module Import
141
- end # module SportDb