Class: SportDb::ReaderBase
- Inherits:
-
Object
- Object
- SportDb::ReaderBase
- Includes:
- LogUtils::Logging, Matcher, Models
- Defined in:
- lib/sportdb/reader.rb
Instance Method Summary collapse
-
#load(name) ⇒ Object
convenience helper for all-in-one reader.
- #load_setup(name) ⇒ Object
Methods included from Matcher
#match_clubs_for_country, #match_leagues_for_country, #match_players_for_country, #match_stadiums_for_country, #match_teams_for_country
Instance Method Details
#load(name) ⇒ Object
convenience helper for all-in-one reader
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/sportdb/reader.rb', line 25 def load( name ) # convenience helper for all-in-one reader logger.debug "enter load( name=>>#{name}<<)" ## formerly also printed -> include_path=>>#{include_path}<< if match_players_for_country( name ) do |country_key| ## country = Country.find_by_key!( country_key ) ## fix-fix-fix-fix-fix-fix: change to new format e.g. from_file, from_zip etc!!! ## reader = PersonDb::PersonReader.new( include_path ) ## reader.read( name, country_id: country.id ) end elsif name =~ /\/squads\/([a-z0-9]{3,})$/ # e.g. ajax.txt bayern.txt etc. ## note: for now assume club (e.g. no dash (-) allowed for country code e.g. br-brazil etc.) team = Team.find_by_key!( $1 ) ## note: pass in @event.id - that is, last seen event (e.g. parsed via GameReader/MatchReader) reader = create_club_squad_reader( name, team_id: team.id, event_id: @event.id ) reader.read() 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 # note: if two letters, assume country key # if three letters, assume team key ## allow three letter codes ## assume three letter code are *team* codes (e.g. fdr, gdr, etc) ## not country code (allows multiple teams per country) if $1.length == 2 ## get national team via country country = Country.find_by_key!( $1 ) ### for now assume country code matches team for now (do NOT forget to downcase e.g. BRA==bra) logger.info " assume country code == team code for #{country.code}" team = Team.find_by_key!( country.code.downcase ) else # assume length == 3 ## get national team directly (use three letter fifa code) team = Team.find_by_key!( $1 ) end ## note: pass in @event.id - that is, last seen event (e.g. parsed via GameReader/MatchReader) reader = create_national_team_squad_reader( name, team_id: team.id, event_id: @event.id ) reader.read() elsif name =~ /(?:^|\/)seasons/ # NB: ^seasons or also possible at-austria!/seasons reader = create_season_reader( name ) reader.read() elsif name =~ /(?:^|\/)assocs/ # NB: ^assocs or also possible national-teams!/assocs reader = create_assoc_reader( name ) reader.read() elsif match_stadiums_for_country( name ) do |country_key| country = Country.find_by_key!( country_key ) reader = create_ground_reader( name, country_id: country.id ) reader.read() end elsif match_leagues_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/leagues/ # auto-add country code (from folder structure) for country-specific leagues # e.g. at/leagues country = Country.find_by_key!( country_key ) reader = create_league_reader( name, club: true, country_id: country.id ) reader.read() end elsif name =~ /(?:^|\/)leagues/ # NB: ^leagues or also possible world!/leagues - NB: make sure goes after leagues_for_country!! reader = create_league_reader( name ) reader.read() elsif match_teams_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/teams/ # auto-add country code (from folder structure) for country-specific teams # e.g. at/teams at/teams.2 de/teams etc. country = Country.find_by_key!( country_key ) reader = create_team_reader( name, country_id: country.id ) reader.read() end elsif match_clubs_for_country( name ) do |country_key| # name =~ /^([a-z]{2})\/clubs/ # auto-add country code (from folder structure) for country-specific clubs # e.g. at/teams at/teams.2 de/teams etc. country = Country.find_by_key!( country_key ) reader = create_team_reader( name, club: true, country_id: country.id ) ## note: always sets club flag to true reader.read() end elsif name =~ /(?:^|\/)teams/ ## fix: check if teams rule above (e.g. /^teams/ )conflicts/matches first ??? ### fix: use new NationalTeamReader ??? why? why not? reader = create_team_reader( name ) ## note: always sets club flag to true / national to true reader.read() elsif name =~ /(?:^|\/)clubs/ ### fix: use new ClubReader ??? why? why not? reader = create_team_reader( name, club: true ) ## note: always sets club flag to true / national to false reader.read() elsif name =~ /\/(\d{4}|\d{4}[_\-]\d{2})(--[^\/]+)?\// || name =~ /\/(\d{4}|\d{4}[_\-]\d{2})$/ # note: allow 2013_14 or 2013-14 (that, is dash or underscore) # note: keep a "public" reference of last event in @event - e.g. used/required by squads etc. eventreader = create_event_reader( name ) eventreader.read() @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 = create_game_reader( name ) reader.read() else logger.error "unknown sportdb fixture type >#{name}<" # todo/fix: exit w/ error end end |
#load_setup(name) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/sportdb/reader.rb', line 16 def load_setup( name ) reader = create_fixture_reader( name ) reader.each do |fixture_name| load( fixture_name ) end end |