lib/sportdb.rb in sportdb-0.9.1 vs lib/sportdb.rb in sportdb-0.9.2

- old
+ new

@@ -71,70 +71,81 @@ ## make constants in Keys availabe (get include in Models) - do NOT pollute/include in SportDB ## make models available in sportdb module by default with namespace # e.g. lets you use Team instead of Models::Team include SportDB::Models + def self.fixtures_rb_test ['leagues', 'seasons', - 'at/teams', - 'at/2011_12/bl', +# 'at/2011_12/bl', # 'at/2011_12/cup', # 'at/2012_13/bl', # 'at/2012_13/cup', -# 'copa/teams', # 'copa/sud_2012_13', - 'america/teams', - 'world/teams', - 'world/quali_2012_13_america' +# 'world/quali_2012_13_america' ] end def self.fixtures_txt_test [ - [ AT_2011_12, 'at/2011_12/bl'], +# [ AT_2011_12, 'at/2011_12/bl'], # [ AT_2012_13, 'at/2012_13/bl'], # [ AT_CUP_2012_13, 'at/2012_13/cup'], # ['copa.sud.2012/13', 'copa/sud_2012_13'], - [ WORLD_QUALI_AMERICA_2012_13, 'world/quali_2012_13_america'] +# [ WORLD_QUALI_AMERICA_2012_13, 'world/quali_2012_13_america'] ] end + def self.team_fixtures + at = Country.find_by_key!( 'at' ) + de = Country.find_by_key!( 'de' ) + en = Country.find_by_key!( 'en' ) + es = Country.find_by_key!( 'es' ) + ro = Country.find_by_key!( 'ro' ) + mx = Country.find_by_key!( 'mx' ) + + [ + [ 'america/teams', { national: true } ], + [ 'euro/teams', { national: true } ], + [ 'world/teams', { national: true } ], + [ 'at/teams', { club: true, country_id: at.id } ], + [ 'de/teams', { club: true, country_id: de.id } ], + [ 'en/teams', { club: true, country_id: en.id } ], + [ 'es/teams', { club: true, country_id: es.id } ], +# [ 'ro/teams', { club: true, country_id: ro.id } ], + [ 'mx/teams', { club: true, country_id: mx.id } ], + [ 'cl/teams', { club: true } ], + [ 'copa/teams', { club: true } ], + [ 'nhl/teams', { club: true } ] + ] + end + def self.fixtures_rb # all builtin ruby fixtures; helper for covenience ['leagues', 'seasons', - 'at/teams', 'at/badges', 'at/2011_12/bl', 'at/2011_12/cup', 'at/2012_13/bl', 'at/2012_13/cup', - 'de/teams', - 'en/teams', - 'es/teams', - 'cl/teams', 'cl/badges', 'cl/2011_12/cl', 'cl/2011_12/el', 'cl/2012_13/cl', 'de/2012_13/bl', 'en/2012_13/pl', - 'euro/teams', 'euro/2008', 'euro/2012', - 'america/teams', 'america/2011', - 'copa/teams', 'copa/sud_2012_13', - 'mx/teams', 'mx/apertura_2012', - 'world/teams', 'world/2010', 'world/quali_2012_13_europe', - 'world/quali_2012_13_america', - 'nhl/teams'] + 'world/quali_2012_13_america' + ] end def self.fixtures_txt [[ AT_2011_12, 'at/2011_12/bl'], [ AT_2012_13, 'at/2012_13/bl'], @@ -149,24 +160,32 @@ [ WORLD_QUALI_EURO_2012_13, 'world/quali_2012_13_europe_c'], [ WORLD_QUALI_AMERICA_2012_13, 'world/quali_2012_13_america']] end end # class Fixtures + def self.team_fixtures + Fixtures.team_fixtures + end + def self.fixtures_rb # all builtin ruby fixtures; helper for covenience Fixtures.fixtures_rb end def self.fixtures_txt Fixtures.fixtures_txt end def self.load_all + ## load teams first + read( team_fixtures ) # converted to plain text fixtures (.rb no longer exist) + load( fixtures_rb ) end def self.read_all + ## todo/fix: remove!! roll into load_all read( fixtures_txt ) end # load built-in (that is, bundled within the gem) named seeds # - pass in an array of seed names e.g. [ 'cl/teams', 'cl/2012_13/cl' ] etc. @@ -182,10 +201,15 @@ # - pass in an array of pairs of event/seed names e.g. [['at.2012/13', 'at/2012_13/bl'], ['cl.2012/13', 'cl/2012_13/cl']] etc. def self.read( ary ) reader = Reader.new ary.each do |rec| - reader.load_fixtures_builtin( rec[0], rec[1] ) # event_key, name + ## todo: check for teams in name too? + if rec[1].nil? || rec[1].kind_of?( Hash ) ## assume team fixtures + reader.load_teams_builtin( rec[0], rec[1] ) ## NB: name goes first than opt more_values hash + else + reader.load_fixtures_builtin( rec[0], rec[1] ) # event_key, name -- assume game fixtures + end end end class Deleter \ No newline at end of file