sportdb-models 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/.gemtest +0 -0
  3. data/HISTORY.md +21 -0
  4. data/Manifest.txt +142 -0
  5. data/README.md +28 -0
  6. data/Rakefile +59 -0
  7. data/config/fixtures/de.yml +46 -0
  8. data/config/fixtures/en.yml +54 -0
  9. data/config/fixtures/es.yml +48 -0
  10. data/config/fixtures/fr.yml +53 -0
  11. data/config/fixtures/it.yml +55 -0
  12. data/config/fixtures/pt.yml +46 -0
  13. data/config/fixtures/ro.yml +55 -0
  14. data/data/seasons.txt +74 -0
  15. data/data/setups/all.txt +5 -0
  16. data/lib/sportdb/calc.rb +279 -0
  17. data/lib/sportdb/deleter.rb +52 -0
  18. data/lib/sportdb/finders/date.rb +374 -0
  19. data/lib/sportdb/finders/goals.rb +260 -0
  20. data/lib/sportdb/finders/scores.rb +122 -0
  21. data/lib/sportdb/lang.rb +216 -0
  22. data/lib/sportdb/matcher.rb +31 -0
  23. data/lib/sportdb/models.rb +259 -0
  24. data/lib/sportdb/models/assoc.rb +106 -0
  25. data/lib/sportdb/models/assoc_assoc.rb +15 -0
  26. data/lib/sportdb/models/badge.rb +14 -0
  27. data/lib/sportdb/models/event.rb +65 -0
  28. data/lib/sportdb/models/event_ground.rb +15 -0
  29. data/lib/sportdb/models/event_team.rb +16 -0
  30. data/lib/sportdb/models/forward.rb +55 -0
  31. data/lib/sportdb/models/game.rb +244 -0
  32. data/lib/sportdb/models/goal.rb +15 -0
  33. data/lib/sportdb/models/ground.rb +100 -0
  34. data/lib/sportdb/models/group.rb +23 -0
  35. data/lib/sportdb/models/group_team.rb +14 -0
  36. data/lib/sportdb/models/league.rb +83 -0
  37. data/lib/sportdb/models/person.rb +21 -0
  38. data/lib/sportdb/models/roster.rb +18 -0
  39. data/lib/sportdb/models/round.rb +22 -0
  40. data/lib/sportdb/models/season.rb +14 -0
  41. data/lib/sportdb/models/stats/alltime_standing.rb +44 -0
  42. data/lib/sportdb/models/stats/alltime_standing_entry.rb +23 -0
  43. data/lib/sportdb/models/stats/event_standing.rb +55 -0
  44. data/lib/sportdb/models/stats/event_standing_entry.rb +21 -0
  45. data/lib/sportdb/models/stats/group_standing.rb +50 -0
  46. data/lib/sportdb/models/stats/group_standing_entry.rb +22 -0
  47. data/lib/sportdb/models/team.rb +119 -0
  48. data/lib/sportdb/models/team_comp.rb +64 -0
  49. data/lib/sportdb/models/utils.rb +78 -0
  50. data/lib/sportdb/models/world/city.rb +21 -0
  51. data/lib/sportdb/models/world/continent.rb +20 -0
  52. data/lib/sportdb/models/world/country.rb +19 -0
  53. data/lib/sportdb/models/world/region.rb +19 -0
  54. data/lib/sportdb/patterns.rb +38 -0
  55. data/lib/sportdb/reader.rb +130 -0
  56. data/lib/sportdb/reader_file.rb +123 -0
  57. data/lib/sportdb/reader_zip.rb +165 -0
  58. data/lib/sportdb/readers/assoc.rb +54 -0
  59. data/lib/sportdb/readers/event.rb +200 -0
  60. data/lib/sportdb/readers/game.rb +877 -0
  61. data/lib/sportdb/readers/ground.rb +53 -0
  62. data/lib/sportdb/readers/league.rb +54 -0
  63. data/lib/sportdb/readers/season.rb +83 -0
  64. data/lib/sportdb/readers/squad_club.rb +201 -0
  65. data/lib/sportdb/readers/squad_national_team.rb +173 -0
  66. data/lib/sportdb/readers/team.rb +53 -0
  67. data/lib/sportdb/schema.rb +373 -0
  68. data/lib/sportdb/standings.rb +178 -0
  69. data/lib/sportdb/stats.rb +27 -0
  70. data/lib/sportdb/utils.rb +89 -0
  71. data/lib/sportdb/utils_date.rb +26 -0
  72. data/lib/sportdb/utils_goals.rb +20 -0
  73. data/lib/sportdb/utils_group.rb +63 -0
  74. data/lib/sportdb/utils_map.rb +44 -0
  75. data/lib/sportdb/utils_round.rb +165 -0
  76. data/lib/sportdb/utils_scores.rb +17 -0
  77. data/lib/sportdb/utils_teams.rb +43 -0
  78. data/lib/sportdb/version.rb +23 -0
  79. data/test/data/at-austria/2013_14/bl.txt +227 -0
  80. data/test/data/at-austria/2013_14/bl.yml +30 -0
  81. data/test/data/at-austria/2013_14/bl_ii.txt +154 -0
  82. data/test/data/at-austria/2013_14/el.txt +4 -0
  83. data/test/data/at-austria/2013_14/el.yml +25 -0
  84. data/test/data/at-austria/2013_14/squads/austria.txt +40 -0
  85. data/test/data/at-austria/2013_14/squads/salzburg.txt +35 -0
  86. data/test/data/at-austria/leagues.txt +11 -0
  87. data/test/data/at-austria/teams.txt +75 -0
  88. data/test/data/at-austria/teams_2.txt +34 -0
  89. data/test/data/national-teams/assocs.txt +231 -0
  90. data/test/data/national-teams/europe/assocs.txt +13 -0
  91. data/test/data/national-teams/europe/teams.txt +13 -0
  92. data/test/data/national-teams/north-america/assocs.txt +10 -0
  93. data/test/data/national-teams/north-america/teams.txt +7 -0
  94. data/test/data/national-teams/teams.txt +19 -0
  95. data/test/data/players/europe/at-austria/players.txt +45 -0
  96. data/test/data/players/europe/de-deutschland/players.txt +41 -0
  97. data/test/data/players/south-america/br-brazil/players.txt +51 -0
  98. data/test/data/world-cup/1930/cup.txt +71 -0
  99. data/test/data/world-cup/1930/cup.yml +23 -0
  100. data/test/data/world-cup/1930/cup_goals.txt +47 -0
  101. data/test/data/world-cup/1930/cup_goals.yml +23 -0
  102. data/test/data/world-cup/1954/cup.txt +90 -0
  103. data/test/data/world-cup/1954/cup.yml +30 -0
  104. data/test/data/world-cup/1962/cup.txt +86 -0
  105. data/test/data/world-cup/1962/cup.yml +32 -0
  106. data/test/data/world-cup/1974/cup.yml +35 -0
  107. data/test/data/world-cup/1974/cup_finals.txt +14 -0
  108. data/test/data/world-cup/1974/cup_i.txt +55 -0
  109. data/test/data/world-cup/1974/cup_ii.txt +34 -0
  110. data/test/data/world-cup/2014/cup.txt +5 -0
  111. data/test/data/world-cup/2014/cup.yml +54 -0
  112. data/test/data/world-cup/2014/squads/br-brazil.txt +46 -0
  113. data/test/data/world-cup/2014/squads/de-deutschland.txt +8 -0
  114. data/test/data/world-cup/2014/squads/jp-japan.txt +30 -0
  115. data/test/data/world-cup/2014/squads/uy-uruguay.txt +32 -0
  116. data/test/data/world-cup/leagues.txt +5 -0
  117. data/test/data/world-cup/seasons_1930.txt +4 -0
  118. data/test/data/world-cup/seasons_1954.txt +4 -0
  119. data/test/data/world-cup/seasons_1962.txt +4 -0
  120. data/test/data/world-cup/seasons_1974.txt +5 -0
  121. data/test/data/world-cup/teams_1930.txt +26 -0
  122. data/test/data/world-cup/teams_1954.txt +30 -0
  123. data/test/data/world-cup/teams_1962.txt +29 -0
  124. data/test/data/world-cup/teams_1974.txt +29 -0
  125. data/test/helper.rb +120 -0
  126. data/test/test_assoc_reader.rb +201 -0
  127. data/test/test_changes.rb +74 -0
  128. data/test/test_cursor.rb +50 -0
  129. data/test/test_date.rb +100 -0
  130. data/test/test_goals.rb +109 -0
  131. data/test/test_lang.rb +130 -0
  132. data/test/test_load.rb +61 -0
  133. data/test/test_reader.rb +88 -0
  134. data/test/test_reader_from_string.rb +65 -0
  135. data/test/test_round_auto.rb +370 -0
  136. data/test/test_round_def.rb +109 -0
  137. data/test/test_round_header.rb +183 -0
  138. data/test/test_scores.rb +70 -0
  139. data/test/test_squad_club_reader.rb +76 -0
  140. data/test/test_squad_national_team_reader.rb +116 -0
  141. data/test/test_standings.rb +279 -0
  142. data/test/test_standings_ii.rb +46 -0
  143. data/test/test_utils.rb +124 -0
  144. data/test/test_winner.rb +95 -0
  145. metadata +378 -0
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ module SportDb
4
+
5
+ # collection of regex patterns for reuse (SportDb specific)
6
+
7
+ ### todo: add a patterns.md page to github ??
8
+ ## - add regexper pics??
9
+
10
+ ############
11
+ # about ruby regexps
12
+ #
13
+ # try the rubular - Ruby regular expression editor and tester
14
+ # -> http://rubular.com
15
+ # code -> ?? by ??
16
+ #
17
+ #
18
+ # Jeff Avallone's Regexper - Shows State-Automata Diagrams
19
+ # try -> http://regexper.com
20
+ # code -> https://github.com/javallone/regexper
21
+ #
22
+ #
23
+ # Regular Expressions | The Bastards Book of Ruby by Dan Nguyen
24
+ # http://ruby.bastardsbook.com/chapters/regexes/
25
+ #
26
+ # move to notes regex|patterns on geraldb.github.io ??
27
+ #
28
+
29
+ TEAM_KEY_PATTERN = '\A[a-z]{3,}\z'
30
+ TEAM_KEY_PATTERN_MESSAGE = "expected three or more lowercase letters a-z /#{TEAM_KEY_PATTERN}/"
31
+
32
+ # must start w/ letter a-z (2 n 3 can be number or underscore _)
33
+ TEAM_CODE_PATTERN = '\A[A-Z][A-Z0-9][A-Z0-9_]?\z'
34
+ TEAM_CODE_PATTERN_MESSAGE = "expected two or three uppercase letters A-Z (and 0-9_; must start with A-Z) /#{TEAM_CODE_PATTERN}/"
35
+
36
+
37
+ end # module SportDb
38
+
@@ -0,0 +1,130 @@
1
+ # encoding: utf-8
2
+
3
+ module SportDb
4
+
5
+ class ReaderBase
6
+
7
+ include LogUtils::Logging
8
+
9
+
10
+ ## make models available in sportdb module by default with namespace
11
+ # e.g. lets you use Team instead of Model::Team
12
+ include SportDb::Models
13
+ include SportDb::Matcher # lets us use match_teams_for_country etc.
14
+
15
+
16
+ def load_setup( name )
17
+ reader = create_fixture_reader( name )
18
+
19
+ reader.each do |fixture_name|
20
+ load( fixture_name )
21
+ end
22
+ end # method load_setup
23
+
24
+
25
+ def load( name ) # convenience helper for all-in-one reader
26
+
27
+ logger.debug "enter load( name=>>#{name}<<)" ## formerly also printed -> include_path=>>#{include_path}<<
28
+
29
+ if match_players_for_country( name ) do |country_key|
30
+ ## country = Country.find_by_key!( country_key )
31
+ ## fix-fix-fix-fix-fix-fix: change to new format e.g. from_file, from_zip etc!!!
32
+ ## reader = PersonDb::PersonReader.new( include_path )
33
+ ## reader.read( name, country_id: country.id )
34
+ end
35
+ elsif name =~ /\/squads\/([a-z0-9]{3,})$/ # e.g. ajax.txt bayern.txt etc.
36
+ ## note: for now assume club (e.g. no dash (-) allowed for country code e.g. br-brazil etc.)
37
+ team = Team.find_by_key!( $1 )
38
+ ## note: pass in @event.id - that is, last seen event (e.g. parsed via GameReader/MatchReader)
39
+ reader = create_club_squad_reader( name, team_id: team.id, event_id: @event.id )
40
+ reader.read()
41
+ elsif name =~ /\/squads\/([a-z]{2,3})-[^\/]+$/
42
+ ## fix: add to country matcher new format
43
+ ## name is country! and parent folder is type name e.g. /squads/br-brazil
44
+
45
+ # note: if two letters, assume country key
46
+ # if three letters, assume team key
47
+
48
+ ## allow three letter codes
49
+ ## assume three letter code are *team* codes (e.g. fdr, gdr, etc)
50
+ ## not country code (allows multiple teams per country)
51
+
52
+ if $1.length == 2
53
+ ## get national team via country
54
+ country = Country.find_by_key!( $1 )
55
+ ### for now assume country code matches team for now (do NOT forget to downcase e.g. BRA==bra)
56
+ logger.info " assume country code == team code for #{country.code}"
57
+ team = Team.find_by_key!( country.code.downcase )
58
+ else # assume length == 3
59
+ ## get national team directly (use three letter fifa code)
60
+ team = Team.find_by_key!( $1 )
61
+ end
62
+ ## note: pass in @event.id - that is, last seen event (e.g. parsed via GameReader/MatchReader)
63
+ reader = create_national_team_squad_reader( name, team_id: team.id, event_id: @event.id )
64
+ reader.read()
65
+ elsif name =~ /(?:^|\/)seasons/ # NB: ^seasons or also possible at-austria!/seasons
66
+ reader = create_season_reader( name )
67
+ reader.read()
68
+ elsif name =~ /(?:^|\/)assocs/ # NB: ^assocs or also possible national-teams!/assocs
69
+ reader = create_assoc_reader( name )
70
+ reader.read()
71
+ elsif match_stadiums_for_country( name ) do |country_key|
72
+ country = Country.find_by_key!( country_key )
73
+ reader = create_ground_reader( name, country_id: country.id )
74
+ reader.read()
75
+ end
76
+ elsif match_leagues_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/leagues/
77
+ # auto-add country code (from folder structure) for country-specific leagues
78
+ # e.g. at/leagues
79
+ country = Country.find_by_key!( country_key )
80
+ reader = create_league_reader( name, club: true, country_id: country.id )
81
+ reader.read()
82
+ end
83
+ elsif name =~ /(?:^|\/)leagues/ # NB: ^leagues or also possible world!/leagues - NB: make sure goes after leagues_for_country!!
84
+ reader = create_league_reader( name )
85
+ reader.read()
86
+ elsif match_teams_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/teams/
87
+ # auto-add country code (from folder structure) for country-specific teams
88
+ # e.g. at/teams at/teams.2 de/teams etc.
89
+ country = Country.find_by_key!( country_key )
90
+ reader = create_team_reader( name, country_id: country.id )
91
+ reader.read()
92
+ end
93
+ elsif match_clubs_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/clubs/
94
+ # auto-add country code (from folder structure) for country-specific clubs
95
+ # e.g. at/teams at/teams.2 de/teams etc.
96
+ country = Country.find_by_key!( country_key )
97
+ reader = create_team_reader( name, club: true, country_id: country.id ) ## note: always sets club flag to true
98
+ reader.read()
99
+ end
100
+ elsif name =~ /(?:^|\/)teams/ ## fix: check if teams rule above (e.g. /^teams/ )conflicts/matches first ???
101
+ ### fix: use new NationalTeamReader ??? why? why not?
102
+ reader = create_team_reader( name ) ## note: always sets club flag to true / national to true
103
+ reader.read()
104
+ elsif name =~ /(?:^|\/)clubs/
105
+ ### fix: use new ClubReader ??? why? why not?
106
+ reader = create_team_reader( name, club: true ) ## note: always sets club flag to true / national to false
107
+ reader.read()
108
+ elsif name =~ /\/(\d{4}|\d{4}[_\-]\d{2})(--[^\/]+)?\// ||
109
+ name =~ /\/(\d{4}|\d{4}[_\-]\d{2})$/
110
+
111
+ # note: allow 2013_14 or 2013-14 (that, is dash or underscore)
112
+
113
+ # note: keep a "public" reference of last event in @event - e.g. used/required by squads etc.
114
+ eventreader = create_event_reader( name )
115
+ eventreader.read()
116
+ @event = eventreader.event
117
+
118
+ # e.g. must match /2012/ or /2012_13/ or /2012--xxx/ or /2012_13--xx/
119
+ # or /2012 or /2012_13 e.g. brazil/2012 or brazil/2012_13
120
+ reader = create_game_reader( name )
121
+ reader.read()
122
+ else
123
+ logger.error "unknown sportdb fixture type >#{name}<"
124
+ # todo/fix: exit w/ error
125
+ end
126
+ end # method load
127
+
128
+
129
+ end # class Reader
130
+ end # module SportDb
@@ -0,0 +1,123 @@
1
+ # encoding: utf-8
2
+
3
+ module SportDb
4
+
5
+ ## todo: "old" classic reader - rename to FileReader ?? why? why not?
6
+
7
+ class Reader < ReaderBase
8
+
9
+ attr_reader :include_path
10
+
11
+ def initialize( include_path, opts={})
12
+ @include_path = include_path
13
+ end
14
+
15
+ def create_fixture_reader( name )
16
+ path = "#{@include_path}/#{name}.txt"
17
+
18
+ logger.info "parsing data (setup) '#{name}' (#{path})..."
19
+
20
+ FixtureReader.from_file( path )
21
+ end
22
+
23
+ def create_club_squad_reader( name, more_attribs={} )
24
+ real_name = name_to_real_name( name )
25
+ path = "#{@include_path}/#{real_name}.txt"
26
+
27
+ logger.info "parsing data (club squad) '#{name}' (#{path})..."
28
+ ClubSquadReader.from_file( path, more_attribs )
29
+ end
30
+
31
+ def create_national_team_squad_reader( name, more_attribs={} )
32
+ real_name = name_to_real_name( name )
33
+ path = "#{@include_path}/#{real_name}.txt"
34
+
35
+ logger.info "parsing data (national team squad) '#{name}' (#{path})..."
36
+ NationalTeamSquadReader.from_file( path, more_attribs )
37
+ end
38
+
39
+ def create_season_reader( name )
40
+ real_name = name_to_real_name( name )
41
+ path = "#{@include_path}/#{real_name}.txt"
42
+
43
+ logger.info "parsing data (season) '#{name}' (#{path})..."
44
+ SeasonReader.from_file( path )
45
+ end
46
+
47
+ def create_assoc_reader( name )
48
+ real_name = name_to_real_name( name )
49
+ path = "#{@include_path}/#{real_name}.txt"
50
+
51
+ logger.info "parsing data (assoc) '#{name}' (#{path})..."
52
+ AssocReader.from_file( path )
53
+ end
54
+
55
+ def create_ground_reader( name, more_attribs={} )
56
+ real_name = name_to_real_name( name )
57
+ path = "#{@include_path}/#{real_name}.txt"
58
+
59
+ logger.info "parsing data (ground) '#{name}' (#{path})..."
60
+ GroundReader.from_file( path, more_attribs )
61
+ end
62
+
63
+ def create_league_reader( name, more_attribs={} )
64
+ real_name = name_to_real_name( name )
65
+ path = "#{@include_path}/#{real_name}.txt"
66
+
67
+ logger.info "parsing data (league) '#{name}' (#{path})..."
68
+ LeagueReader.from_file( path, more_attribs )
69
+ end
70
+
71
+ def create_team_reader( name, more_attribs={} )
72
+ real_name = name_to_real_name( name )
73
+ path = "#{@include_path}/#{real_name}.txt"
74
+
75
+ logger.info "parsing data (team) '#{name}' (#{path})..."
76
+ TeamReader.from_file( path, more_attribs )
77
+ end
78
+
79
+ def create_event_reader( name, more_attribs={} )
80
+ real_name = name_to_real_name( name )
81
+ path = "#{@include_path}/#{real_name}.yml"
82
+
83
+ logger.info "parsing data (event) '#{name}' (#{path})..."
84
+ EventReader.from_file( path, more_attribs )
85
+ end
86
+
87
+ def create_game_reader( name, more_attribs={} )
88
+ real_name = name_to_real_name( name )
89
+
90
+ ## NOTE: pass in .yml as path (that is, event config!!!!)
91
+ path = "#{@include_path}/#{real_name}.yml"
92
+
93
+ logger.info "parsing data (fixture) '#{name}' (#{path})..."
94
+ GameReader.from_file( path, more_attribs )
95
+ end
96
+
97
+
98
+ def create_person_reader( name, more_attribs={} )
99
+ ## fix-fix-fix: change to new format e.g. from_file, from_zip etc!!!
100
+ ## reader = PersonDb::PersonReader.new( include_path )
101
+ # reader.read( name, country_id: country.id )
102
+ end
103
+
104
+ private
105
+
106
+ def name_to_real_name( name )
107
+ # map name to real_name path
108
+ # name might include !/ for virtual path (gets cut off)
109
+ # e.g. at-austria!/w-wien/beers becomse w-wien/beers
110
+ pos = name.index( '!/')
111
+ if pos.nil?
112
+ name # not found; real path is the same as name
113
+ else
114
+ # cut off everything until !/ e.g.
115
+ # at-austria!/w-wien/beers becomes
116
+ # w-wien/beers
117
+ name[ (pos+2)..-1 ]
118
+ end
119
+ end # method name_to_real_name
120
+
121
+
122
+ end # class Reader
123
+ end # module SportDb
@@ -0,0 +1,165 @@
1
+ # encoding: utf-8
2
+
3
+ module SportDb
4
+
5
+
6
+ class ZipReader < ReaderBase
7
+
8
+ def initialize( name, include_path, opts = {} )
9
+
10
+ ## todo/fix: make include_path an opts (included in opts?) - why? why not??
11
+
12
+ path = "#{include_path}/#{name}.zip"
13
+ ## todo: check if zip exists
14
+
15
+ @zip_file = Zip::File.open( path ) ## NOTE: do NOT create if file is missing; let it crash
16
+
17
+ ### allow prefix (path) in name
18
+ ### e.g. assume all files relative to setup manifest
19
+ ## e.g. at-austria-master/setups/all.txt or
20
+ ## be-belgium-master/setups/all.txt
21
+ ## for
22
+ ## setups/all.txt
23
+ ###
24
+ ## will get (re)set w/ fixture/setup reader
25
+ ##
26
+ ## todo/fix: change/rename to @relative_path ?? - why? why not?
27
+ @zip_prefix = ''
28
+ end
29
+
30
+ def close
31
+ ## todo/check: add a close method - why? why not ???
32
+ @zip_file.close
33
+ end
34
+
35
+
36
+ def create_fixture_reader( name )
37
+ ## e.g. pass in => setups/all or setups/test etc. e.g. w/o .txt extension
38
+ query = "**/#{name}.txt"
39
+
40
+ ## note: returns an array of Zip::Entry
41
+ candidates = @zip_file.glob( query )
42
+ pp candidates
43
+
44
+ ## use first candidates entry as match
45
+ ## todo/fix: issue warning if more than one entries/matches!!
46
+
47
+ ## get fullpath e.g. at-austria-master/setups/all.txt
48
+ path = candidates[0].name
49
+ logger.debug " zip entry path >>#{path}<<"
50
+
51
+ ## cut-off at-austria-master/ NOTE: includes trailing slash (if present)
52
+ ## logger.debug " path.size #{path.size} >>#{path}<<"
53
+ ## logger.debug " name.size #{name.size+4} >>#{name}<<"
54
+
55
+ ## note: add +4 for extension (.txt)
56
+ @zip_prefix = path[ 0...(path.size-(name.size+4)) ]
57
+ logger.debug " zip entry prefix >>#{@zip_prefix}<<"
58
+
59
+ logger.info "parsing data in zip '#{name}' (#{path})..."
60
+
61
+ FixtureReader.from_zip( @zip_file, path )
62
+ end
63
+
64
+ def create_club_squad_reader( name, more_attribs={} )
65
+ path = name_to_zip_entry_path( name )
66
+
67
+ logger.info "parsing data in zip (club squad) '#{name}' (#{path})..."
68
+ ClubSquadReader.from_zip( @zip_file, path, more_attribs )
69
+ end
70
+
71
+ def create_national_team_squad_reader( name, more_attribs={} )
72
+ path = name_to_zip_entry_path( name )
73
+
74
+ logger.info "parsing data in zip (national team squad) '#{name}' (#{path})..."
75
+ NationalTeamSquadReader.from_zip( @zip_file, path, more_attribs )
76
+ end
77
+
78
+ def create_season_reader( name )
79
+ path = name_to_zip_entry_path( name )
80
+
81
+ logger.info "parsing data in zip (season) '#{name}' (#{path})..."
82
+ SeasonReader.from_zip( @zip_file, path )
83
+ end
84
+
85
+ def create_assoc_reader( name )
86
+ path = name_to_zip_entry_path( name )
87
+
88
+ logger.info "parsing data in zip (assoc) '#{name}' (#{path})..."
89
+ AssocReader.from_zip( @zip_file, path )
90
+ end
91
+
92
+ def create_ground_reader( name, more_attribs={} )
93
+ path = name_to_zip_entry_path( name )
94
+
95
+ logger.info "parsing data in zip (ground) '#{name}' (#{path})..."
96
+ GroundReader.from_zip( @zip_file, path, more_attribs )
97
+ end
98
+
99
+ def create_league_reader( name, more_attribs={} )
100
+ path = name_to_zip_entry_path( name )
101
+
102
+ logger.info "parsing data in zip (league) '#{name}' (#{path})..."
103
+ LeagueReader.from_zip( @zip_file, path, more_attribs )
104
+ end
105
+
106
+ def create_team_reader( name, more_attribs={} )
107
+ path = name_to_zip_entry_path( name )
108
+
109
+ logger.info "parsing data in zip (team) '#{name}' (#{path})..."
110
+ TeamReader.from_zip( @zip_file, path, more_attribs )
111
+ end
112
+
113
+ def create_event_reader( name, more_attribs={} )
114
+ path = name_to_zip_entry_path( name, '.yml' ) ## NOTE: use .yml extension
115
+
116
+ logger.info "parsing data in zip (event) '#{name}' (#{path})..."
117
+ EventReader.from_zip( @zip_file, path, more_attribs )
118
+ end
119
+
120
+ def create_game_reader( name, more_attribs={} )
121
+ ## NOTE: pass in .yml as path (that is, event config!!!!)
122
+ path = name_to_zip_entry_path( name, '.yml' ) ## NOTE: use .yml extension
123
+
124
+ logger.info "parsing data in zip (fixture) '#{name}' (#{path})..."
125
+ GameReader.from_zip( @zip_file, path, more_attribs )
126
+ end
127
+
128
+
129
+ def create_person_reader( name, more_attribs={} )
130
+ ## fix-fix-fix: change to new format e.g. from_file, from_zip etc!!!
131
+ ## reader = PersonDb::PersonReader.new( include_path )
132
+ # reader.read( name, country_id: country.id )
133
+ end
134
+
135
+ private
136
+
137
+ def path_to_real_path( path )
138
+ # map name to name_real_path
139
+ # name might include !/ for virtual path (gets cut off)
140
+ # e.g. at-austria!/w-wien/beers becomse w-wien/beers
141
+ pos = path.index( '!/')
142
+ if pos.nil?
143
+ path # not found; real path is the same as name
144
+ else
145
+ # cut off everything until !/ e.g.
146
+ # at-austria!/w-wien/beers becomes
147
+ # w-wien/beers
148
+ path[ (pos+2)..-1 ]
149
+ end
150
+ end
151
+
152
+ def name_to_zip_entry_path( name, extension='.txt' )
153
+ path = "#{name}#{extension}"
154
+
155
+ real_path = path_to_real_path( path )
156
+
157
+ # NOTE: add possible zip entry prefix path
158
+ # (if present includes trailing slash e.g. /)
159
+ entry_path = "#{@zip_prefix}#{real_path}"
160
+ entry_path
161
+ end
162
+
163
+ end # class ZipReader
164
+
165
+ end # module SportDb