sportdb-formats 1.1.6 → 1.2.0

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.
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
@@ -1,134 +1,134 @@
1
- # encoding: utf-8
2
-
3
- module SportDb
4
- module Import
5
-
6
-
7
- class ClubHistoryIndex
8
-
9
- def self.build( path )
10
- pack = Package.new( path ) ## lets us use direcotry or zip archive
11
-
12
- recs = []
13
- pack.each_clubs_history do |entry|
14
- recs += ClubHistoryReader.parse( entry.read )
15
- end
16
- recs
17
-
18
- index = new
19
- index.add( recs )
20
- index
21
- end
22
-
23
-
24
-
25
- def catalog() Import.catalog; end
26
-
27
- ## note: keep name history for now separate from
28
- ## from club struct - why? why not?
29
- ## later yes, yes, yes, merge name history into club struct!!!!!
30
- ##
31
- ## for now the name history is experimental
32
-
33
-
34
- def initialize
35
- @clubs = {} ## clubs (indexed) by canonical name
36
- @errors = []
37
- end
38
-
39
- attr_reader :errors
40
- def errors?() @errors.empty? == false; end
41
-
42
- def mappings() @clubs; end ## todo/check: rename to records or histories or something - why? why not?
43
-
44
-
45
- def add_history( club_rec, keyword, season, args )
46
- ## note use season obj for now (and NOT key) - why? why not?
47
- rec = @clubs[ club_rec.name ] ||= []
48
-
49
- rec << [season, [keyword, args]]
50
-
51
- ## note: always keep records sorted by season_key for now
52
- ## check if 2010 and 2010/11 is in order using alpha sort?? (see argentina)
53
- rec.sort! { |l,r| r[0] <=> l[0] }
54
- end
55
-
56
-
57
- def add( rec_or_recs ) ## add club record / alt_names
58
- recs = rec_or_recs.is_a?( Array ) ? rec_or_recs : [rec_or_recs] ## wrap (single) rec in array
59
-
60
- recs.each do |rec|
61
-
62
- keyword = rec[0]
63
- season_key = rec[1]
64
- args = rec[2..-1] ## get rest of args e.g. one, two or more
65
-
66
- ## note: for now only add (re)name history season records,
67
- ## that is, skip MERGE and BANKRUPT for now
68
- ## and incl. only RENAME, REFORM, MOVE for now
69
- next if ['MERGE', 'BANKRUPT'].include?( keyword )
70
-
71
-
72
- name_old = strip_geo( args[0][0] ) ## note: strip optional geo part from name
73
- name_new = strip_geo( args[1][0] )
74
-
75
- country_old = args[0][1]
76
- country_new = args[1][1]
77
-
78
- club_old = catalog.clubs.find_by!( name: name_old, country: country_old )
79
- club_new = catalog.clubs.find_by!( name: name_new, country: country_new )
80
-
81
- ## note use season obj for now (and NOT key) - why? why not?
82
- season = Season.parse( season_key )
83
-
84
- ## todo/check:
85
- ## check if club_old and club_new reference different club record!!
86
- ## examples - RB II -> Liefering ?? or
87
- ## FC Pasching -> OOE Juniors ??
88
- ## Austria Salzburg -> RB Salburg ??
89
- ## for now always add name history to both - why? why not?
90
-
91
- add_history( club_old, keyword, season, args )
92
- ## note: allow for now different club references
93
- ## but maybe warn later - why? why not?
94
- ## add history to both for now
95
- add_history( club_new, keyword, season, args ) if club_old != club_new
96
- end # each rec
97
- end # method add
98
-
99
-
100
- #### todo/check: move as method to club struct later - to always use club reference
101
- ## returns (simply) name as string for now or nil - why? why not?
102
- #
103
- # history entry example
104
- # Arsenal FC"=>
105
- # [[1927/28, ["RENAME", [["The Arsenal FC, London", "eng"], ["Arsenal FC", "eng"]]]],
106
- # [1914/15, ["RENAME", [["Woolwich Arsenal FC, London", "eng"], ["The Arsenal FC", "eng"]]]],
107
- # [1892/93, ["RENAME", [["Royal Arsenal FC, London", "eng"], ["Woolwich Arsenal FC", "eng"]]]]],
108
- def find_name_by( name:, season: )
109
- recs = @clubs[ name ]
110
- if recs
111
- season = Season( season ) ## make sure season is a season obj (and NOT a string)
112
- ## check season records for name; use linear search (assume only few records)
113
- recs.each do |rec|
114
- if season >= rec[0]
115
- return strip_geo( rec[1][1][1][0] ) # use second arg
116
- end
117
- end
118
- ## if we get here use last name
119
- strip_geo( recs[-1][1][1][0][0] ) # use first arg
120
- else
121
- nil
122
- end
123
- end
124
-
125
- ##################
126
- ## helpers
127
- def strip_geo( name )
128
- ## e.g. Arsenal, London => Arsenal
129
- name.split(',')[0].strip
130
- end
131
- end # class ClubHistoryIndex
132
-
133
- end # module Import
134
- end # module SportDb
1
+ # encoding: utf-8
2
+
3
+ module SportDb
4
+ module Import
5
+
6
+
7
+ class ClubHistoryIndex
8
+
9
+ def self.build( path )
10
+ pack = Package.new( path ) ## lets us use direcotry or zip archive
11
+
12
+ recs = []
13
+ pack.each_clubs_history do |entry|
14
+ recs += ClubHistoryReader.parse( entry.read )
15
+ end
16
+ recs
17
+
18
+ index = new
19
+ index.add( recs )
20
+ index
21
+ end
22
+
23
+
24
+
25
+ def catalog() Import.catalog; end
26
+
27
+ ## note: keep name history for now separate from
28
+ ## from club struct - why? why not?
29
+ ## later yes, yes, yes, merge name history into club struct!!!!!
30
+ ##
31
+ ## for now the name history is experimental
32
+
33
+
34
+ def initialize
35
+ @clubs = {} ## clubs (indexed) by canonical name
36
+ @errors = []
37
+ end
38
+
39
+ attr_reader :errors
40
+ def errors?() @errors.empty? == false; end
41
+
42
+ def mappings() @clubs; end ## todo/check: rename to records or histories or something - why? why not?
43
+
44
+
45
+ def add_history( club_rec, keyword, season, args )
46
+ ## note use season obj for now (and NOT key) - why? why not?
47
+ rec = @clubs[ club_rec.name ] ||= []
48
+
49
+ rec << [season, [keyword, args]]
50
+
51
+ ## note: always keep records sorted by season_key for now
52
+ ## check if 2010 and 2010/11 is in order using alpha sort?? (see argentina)
53
+ rec.sort! { |l,r| r[0] <=> l[0] }
54
+ end
55
+
56
+
57
+ def add( rec_or_recs ) ## add club record / alt_names
58
+ recs = rec_or_recs.is_a?( Array ) ? rec_or_recs : [rec_or_recs] ## wrap (single) rec in array
59
+
60
+ recs.each do |rec|
61
+
62
+ keyword = rec[0]
63
+ season_key = rec[1]
64
+ args = rec[2..-1] ## get rest of args e.g. one, two or more
65
+
66
+ ## note: for now only add (re)name history season records,
67
+ ## that is, skip MERGE and BANKRUPT for now
68
+ ## and incl. only RENAME, REFORM, MOVE for now
69
+ next if ['MERGE', 'BANKRUPT'].include?( keyword )
70
+
71
+
72
+ name_old = strip_geo( args[0][0] ) ## note: strip optional geo part from name
73
+ name_new = strip_geo( args[1][0] )
74
+
75
+ country_old = args[0][1]
76
+ country_new = args[1][1]
77
+
78
+ club_old = catalog.clubs.find_by!( name: name_old, country: country_old )
79
+ club_new = catalog.clubs.find_by!( name: name_new, country: country_new )
80
+
81
+ ## note use season obj for now (and NOT key) - why? why not?
82
+ season = Season.parse( season_key )
83
+
84
+ ## todo/check:
85
+ ## check if club_old and club_new reference different club record!!
86
+ ## examples - RB II -> Liefering ?? or
87
+ ## FC Pasching -> OOE Juniors ??
88
+ ## Austria Salzburg -> RB Salburg ??
89
+ ## for now always add name history to both - why? why not?
90
+
91
+ add_history( club_old, keyword, season, args )
92
+ ## note: allow for now different club references
93
+ ## but maybe warn later - why? why not?
94
+ ## add history to both for now
95
+ add_history( club_new, keyword, season, args ) if club_old != club_new
96
+ end # each rec
97
+ end # method add
98
+
99
+
100
+ #### todo/check: move as method to club struct later - to always use club reference
101
+ ## returns (simply) name as string for now or nil - why? why not?
102
+ #
103
+ # history entry example
104
+ # Arsenal FC"=>
105
+ # [[1927/28, ["RENAME", [["The Arsenal FC, London", "eng"], ["Arsenal FC", "eng"]]]],
106
+ # [1914/15, ["RENAME", [["Woolwich Arsenal FC, London", "eng"], ["The Arsenal FC", "eng"]]]],
107
+ # [1892/93, ["RENAME", [["Royal Arsenal FC, London", "eng"], ["Woolwich Arsenal FC", "eng"]]]]],
108
+ def find_name_by( name:, season: )
109
+ recs = @clubs[ name ]
110
+ if recs
111
+ season = Season( season ) ## make sure season is a season obj (and NOT a string)
112
+ ## check season records for name; use linear search (assume only few records)
113
+ recs.each do |rec|
114
+ if season >= rec[0]
115
+ return strip_geo( rec[1][1][1][0] ) # use second arg
116
+ end
117
+ end
118
+ ## if we get here use last name
119
+ strip_geo( recs[-1][1][1][0][0] ) # use first arg
120
+ else
121
+ nil
122
+ end
123
+ end
124
+
125
+ ##################
126
+ ## helpers
127
+ def strip_geo( name )
128
+ ## e.g. Arsenal, London => Arsenal
129
+ name.split(',')[0].strip
130
+ end
131
+ end # class ClubHistoryIndex
132
+
133
+ end # module Import
134
+ end # module SportDb