Permalink
Browse files

add read_builtin

  • Loading branch information...
1 parent b34f735 commit ab73e65caa0a1094089ffbc507392486a1344baa @geraldb geraldb committed Aug 6, 2013
View
@@ -7,6 +7,8 @@ config/fixtures.de.yml
config/fixtures.en.yml
config/fixtures.es.yml
config/fixtures.pt.yml
+data/seasons.txt
+data/setups/all.yml
lib/sportdb.rb
lib/sportdb/cli/main.rb
lib/sportdb/cli/opts.rb
View
@@ -0,0 +1,28 @@
+###
+# use period for season? why? why not?
+# - semantic hairsplitting? make it an alias? why? why not? who cares?
+
+2014/15
+2013/14
+2012/13 # use 2012-13 or 2012_13 or 2012.13 or 2012+13 ???
+2011/12
+2010/11
+2009/10
+2008/09
+2007/08
+2015 # years only
+2014
+2013
+2012
+2011
+2010
+2009
+2008
+2014.1
+2014.2
+2013.1 # e.g. Liga MX has two (complete) seasons in *one* year e.g. Clausura 2013 n Apertura 2013
+2013.2
+2012.1
+2012.2
+
+### for 2013.1 use 2013_I 2013-I 2013.I n 2013-II 2013.II or 2013.A n 2013.B
View
@@ -0,0 +1,5 @@
+############################
+# builtin seed data
+
+data:
+- seasons
View
@@ -74,7 +74,7 @@
-module SportDB
+module SportDb
def self.banner
"sportdb #{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
@@ -87,6 +87,10 @@ def self.root
def self.config_path
"#{root}/config"
end
+
+ def self.data_path
+ "#{root}/data"
+ end
def self.lang
# todo/fix: find a better way for single instance ??
@@ -116,6 +120,10 @@ def self.read_all( include_path ) # convenience helper
read_setup( 'setups/all', include_path )
end
+ def self.read_builtin
+ read_setup( 'setups/all', data_path )
+ end
+
# load built-in (that is, bundled within the gem) named plain text seeds
# - pass in an array of pairs of event/seed names e.g.
View
@@ -97,6 +97,9 @@ def connect_to_db( options )
LogDb.create
WorldDb.create
SportDb.create
+
+ SportDb.read_builtin # e.g. seasons.txt etc
+
puts 'Done.'
end # action
end # command create
@@ -125,6 +128,8 @@ def connect_to_db( options )
LogDb.create
WorldDb.create
SportDb.create
+
+ SportDb.read_builtin # e.g. seasons.txt etc
WorldDb.read_all( opts.world_data_path )
SportDb.read_setup( "setups/#{setup}", opts.data_path )
@@ -152,7 +157,10 @@ def connect_to_db( options )
## todo: document optional setup profile arg (defaults to all)
setup = args[0] || 'all'
- SportDb.delete! if o[:delete].present?
+ if o[:delete].present?
+ SportDb.delete!
+ SportDb.read_builtin # NB: reload builtins (e.g. seasons etc.)
+ end
SportDb.read_setup( "setups/#{setup}", opts.data_path )
puts 'Done.'
@@ -171,7 +179,10 @@ def connect_to_db( options )
connect_to_db( opts )
- SportDb.delete! if o[:delete].present?
+ if o[:delete].present?
+ SportDb.delete!
+ SportDb.read_builtin # NB: reload builtins (e.g. seasons etc.)
+ end
reader = SportDb::Reader.new( opts.data_path )
@@ -106,78 +106,78 @@ module Fixtures # use shortcut/alias Fx?
BR_TEAMS +
MX_TEAMS +
[
- 'club/america/teams_c',
- 'club/america/teams_n',
- 'club/america/teams_s',
+ 'america/teams_c',
+ 'america/teams_n',
+ 'america/teams_s',
]
AR_FIXTURES = []
### todo: ? get event_key automatically from event_reader ?? why? why not??
BR_FIXTURES = [
- ['br.2013', 'br/2013/cb' ]
+ 'br/2013/cb'
]
MX_FIXTURES = [
- ['mx.apertura.2012.2', 'mx/2012/apertura' ],
- ['mx.clausura.2013.1', 'mx/2013/clausura' ]
+ 'mx/2012/apertura',
+ 'mx/2013/clausura'
]
AT_FIXTURES = [
- ['at.2011/12', 'at/2011_12/bl' ],
- ['at.cup.2011/12', 'at/2011_12/cup' ],
- ['at.2012/13', 'at/2012_13/bl', 'at/2012_13/bl2'],
- ['at.cup.2012/13', 'at/2012_13/cup']
+ 'at/2011_12/bl',
+ 'at/2011_12/cup',
+ 'at/2012_13/bl',
+ 'at/2012_13/cup'
]
DE_FIXTURES = [
- ['de.2012/13', 'de/2012_13/bl' ]
+ 'de/2012_13/bl'
]
EN_FIXTURES = [
- ['en.2012/13', 'en/2012_13/pl' ]
+ 'en/2012_13/pl'
]
RO_FIXTURES = [
- ['ro.2012/13', 'ro/2012_13/l1' ]
+ 'ro/2012_13/l1'
]
EUROPE_FIXTURES = [
- ['euro.2008', 'europe/2008/euro'],
- ['euro.2012', 'europe/2012/euro'],
+ 'euro-cup!/2008/euro',
+ 'euro-cup!/2012/euro'
]
AMERICA_FIXTURES = [
- ['america.copa.2011', 'america/2011/copa'],
- ['america.gold.2011', 'america/2011/gold'],
- ['america.gold.2013', 'america/2013/gold'],
- ['america.copa.2015', 'america/2015/copa'],
+ 'america/2011/copa',
+ 'america/2011/gold',
+ 'america/2013/gold',
+ 'america/2015/copa'
]
WORLD_FIXTURES = [
- ['world.conf.2009', 'world/2009/conf'],
- ['world.2010', 'world/2010/cup'],
- ['world.quali.america.2014', 'world/2014/quali_america'],
- ['world.quali.europe.c.2014', 'world/2014/quali_europe_c'],
- ['world.quali.europe.2014', 'world/2014/quali_europe', 'world/2014/quali_europe_c', 'world/2014/quali_europe_i'],
- ['world.2014', 'world/2014/cup'],
+ 'world/2009/conf',
+ 'world/2010/cup',
+ 'world/2014/quali_america',
+ 'world/2014/quali_europe_c',
+ 'world/2014/quali_europe',
+ 'world/2014/cup'
]
CLUB_EUROPE_FIXTURES = [
- ['cl.2011/12', 'club/europe/2011_12/cl'],
- ['el.2011/12', 'club/europe/2011_12/el'],
- ['cl.2012/13', 'club/europe/2012_13/cl'],
- ['el.2012/13', 'club/europe/2012_13/el'],
+ 'club/europe/2011_12/cl',
+ 'club/europe/2011_12/el',
+ 'club/europe/2012_13/cl',
+ 'club/europe/2012_13/el'
]
CLUB_AMERICA_FIXTURES = [
- ['america.cl.2011/12', 'club/america/2011_12/cl'],
- ['copa.libertadores.2012', 'club/america/2012/libertadores' ],
- ['copa.sud.2012', 'club/america/2012/sud'],
- ['america.cl.2012/13', 'club/america/2012_13/cl'],
- ['copa.libertadores.2013', 'club/america/2013/libertadores' ]
+ 'club/america/2011_12/cl',
+ 'club/america/2012/libertadores',
+ 'club/america/2012/sud',
+ 'club/america/2012_13/cl',
+ 'club/america/2013/libertadores'
]
def self.all
View
@@ -12,9 +12,9 @@ def initialize
# load word lists
- @fixtures_en = YAML.load( File.read_utf8( "#{SportDB.config_path}/fixtures.en.yml" ))
- @fixtures_de = YAML.load( File.read_utf8( "#{SportDB.config_path}/fixtures.de.yml" ))
- @fixtures_es = YAML.load( File.read_utf8( "#{SportDB.config_path}/fixtures.es.yml" ))
+ @fixtures_en = YAML.load( File.read_utf8( "#{SportDb.config_path}/fixtures.en.yml" ))
+ @fixtures_de = YAML.load( File.read_utf8( "#{SportDb.config_path}/fixtures.de.yml" ))
+ @fixtures_es = YAML.load( File.read_utf8( "#{SportDb.config_path}/fixtures.es.yml" ))
@fixtures = {
'en' => @fixtures_en,
@@ -214,9 +214,9 @@ def analyze( path )
### todo/fix:
# remove comment lines and end of line comments from text
- en = count_words_in_text( SportDB.lang.words_en, text )
- de = count_words_in_text( SportDB.lang.words_de, text )
- es = count_words_in_text( SportDB.lang.words_es, text )
+ en = count_words_in_text( SportDb.lang.words_en, text )
+ de = count_words_in_text( SportDb.lang.words_de, text )
+ es = count_words_in_text( SportDb.lang.words_es, text )
lang_counts = [
[ 'en', en ],
@@ -24,7 +24,7 @@ class League < ActiveRecord::Base ; end
module WorldDb::Models
# add alias? why? why not? # is there a better way?
- # - just include SportDB::Models - why? why not?
+ # - just include SportDb::Models - why? why not?
# - just include once in loader??
Team = SportDb::Models::Team
League = SportDb::Models::League
View
@@ -381,7 +381,7 @@ def load_fixtures( event_key, name ) # load from file system
logger.info "parsing data '#{name}' (#{path})..."
- SportDB.lang.lang = LangChecker.new.analyze( path )
+ SportDb.lang.lang = LangChecker.new.analyze( path )
reader = LineReader.new( path )
@@ -397,7 +397,7 @@ def load_records( name, more_attribs={} )
logger.info "parsing data '#{name}' (#{path})..."
- ### SportDB.lang.lang = LangChecker.new.analyze( name, include_path )
+ ### SportDb.lang.lang = LangChecker.new.analyze( name, include_path )
reader = LineReader.new( path )
@@ -476,7 +476,7 @@ def load_rosters( name )
logger.info "parsing data '#{name}' (#{path})..."
- ### SportDB.lang.lang = LangChecker.new.analyze( name, include_path )
+ ### SportDb.lang.lang = LangChecker.new.analyze( name, include_path )
reader = LineReader.new( path )
@@ -550,7 +550,7 @@ def load_races( name )
logger.info "parsing data '#{name}' (#{path})..."
- ### SportDB.lang.lang = LangChecker.new.analyze( name, include_path )
+ ### SportDb.lang.lang = LangChecker.new.analyze( name, include_path )
reader = LineReader.new( path )
@@ -615,7 +615,7 @@ def load_teams( name, more_attribs={} )
private
- include SportDB::FixtureHelpers
+ include SportDb::FixtureHelpers
def load_fixtures_worker( event_key, reader )
View
@@ -1,9 +1,10 @@
module SportDb
- VERSION = '1.6.18'
+ VERSION = '1.7.0'
end
+
###########################################
-## fix: remove old alias for SportDb
+# fix: remove old alias for SportDb
SportDB = SportDb

0 comments on commit ab73e65

Please sign in to comment.