lib/sportdb/reader.rb in sportdb-1.8.23 vs lib/sportdb/reader.rb in sportdb-1.8.24

- old
+ new

@@ -71,31 +71,44 @@ end elsif name =~ /^tracks/ # e.g. tracks.txt in ski.db reader = TrackReader.new( include_path ) reader.read( name ) elsif name =~ /^drivers/ # e.g. drivers.txt in formula1.db - load_persons( name ) + reader = PersonDb::PersonReader.new( include_path ) + reader.read( name ) elsif match_players_for_country( name ) do |country_key| country = Country.find_by_key!( country_key ) - load_persons( name, country_id: country.id ) + reader = PersonDb::PersonReader.new( include_path ) + reader.read( name, country_id: country.id ) end elsif match_skiers_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/skiers/ # auto-add country code (from folder structure) for country-specific skiers (persons) # e.g. at/skiers or at-austria/skiers.men country = Country.find_by_key!( country_key ) - load_persons( name, country_id: country.id ) + reader = PersonDb::PersonReader.new( include_path ) + reader.read( name, country_id: country.id ) end elsif name =~ /^skiers/ # e.g. skiers.men.txt in ski.db - load_persons( name ) + reader = PersonDb::PersonReader.new( include_path ) + reader.read( name ) elsif name =~ /^teams/ # e.g. teams.txt in formula1.db reader = TeamReader.new( include_path ) reader.read( name ) elsif name =~ /\/races/ # e.g. 2013/races.txt in formula1.db + ## fix/bug: NOT working for now; sorry + # need to read event first and pass along to read (event_id: event.id) etc. reader = RaceReader.new( include_path ) reader.read( name ) + elsif name =~ /\/squads\/([a-z]{2,3})-[^\/]+$/ + ## fix: add to country matcher new format + ## name is country! and parent folder is type name e.g. /squads/br-brazil + country = Country.find_by_key!( $1 ) + reader = NationalTeamReader.new( include_path ) + ## note: pass in @event.id - that is, last seen event (e.g. parsed via GameReader/MatchReader) + reader.read( name, country_id: country.id, event_id: @event.id ) elsif name =~ /\/squads/ || name =~ /\/rosters/ # e.g. 2013/squads.txt in formula1.db - reader = RosterReader.new( include_path ) + reader = RaceTeamReader.new( include_path ) reader.read( name ) elsif name =~ /\/([0-9]{2})-/ race_pos = $1.to_i # NB: assume @event is set from previous load race = Race.find_by_event_id_and_pos( @event.id, race_pos ) @@ -129,10 +142,16 @@ elsif name =~ /(?:^|\/)teams/ reader = TeamReader.new( include_path ) reader.read( name, club: is_club_fixture?( name ) ) elsif name =~ /\/(\d{4}|\d{4}_\d{2})(--[^\/]+)?\// || name =~ /\/(\d{4}|\d{4}_\d{2})$/ + + # note: keep a "public" reference of last event in @event - e.g. used/required by squads etc. + eventreader = EventReader.new( include_path ) + eventreader.read( name ) + @event = eventreader.event + # e.g. must match /2012/ or /2012_13/ or /2012--xxx/ or /2012_13--xx/ # or /2012 or /2012_13 e.g. brazil/2012 or brazil/2012_13 reader = GameReader.new( include_path ) reader.read( name ) else @@ -140,18 +159,7 @@ # todo/fix: exit w/ error end end # method load - #### - # fix: move to persondb for (re)use - - def load_persons( name, more_attribs={} ) - reader = PersonDb::PersonReader.new( include_path ) - ## fix: add more_attribs !!!!! -- check other readers as an example - ## - gets added to new or read?? - reader.read( name ) - end # load_persons - - end # class Reader end # module SportDb