lib/sportdb/reader.rb in sportdb-1.7.1 vs lib/sportdb/reader.rb in sportdb-1.7.2
- old
+ new
@@ -2,10 +2,12 @@
module SportDb
module Matcher
+ include WorldDb::Matcher
+
def match_leagues_for_country( name, &blk )
match_xxx_for_country( name, 'leagues', blk )
end
def match_teams_for_country( name, &blk )
@@ -21,12 +23,10 @@
## make models available in sportdb module by default with namespace
# e.g. lets you use Team instead of Models::Team
include SportDb::Models
-
- include WorldDb::Matcher
include SportDb::Matcher # lets us use match_teams_for_country etc.
attr_reader :include_path
@@ -270,11 +270,19 @@
# move parsing code to model
reader = HashReaderV2.new( name, include_path )
event_attribs = {}
+
+ ## set default sources to basename by convention
+ # e.g 2013_14/bl => bl
+ # etc.
+ # use fixtures/sources: to override default
+ event_attribs[ 'sources' ] = File.basename( name )
+ event_attribs[ 'config' ] = File.basename( name ) # name a of .yml file
+
reader.each_typed do |key, value|
## puts "processing event attrib >>#{key}<< >>#{value}<<..."
if key == 'league'
@@ -323,17 +331,21 @@
event_attribs['team_ids'] = team_ids
elsif key == 'team3'
## for now always assume false # todo: fix - use value and convert to boolean if not boolean
event_attribs['team3'] = false
- elsif key == 'fixtures'
- ## skip fixtures for now (NOT yet stored in db; for now reload file to get fixtures)
+ elsif key == 'fixtures' || key == 'sources'
+ if value.kind_of?(Array)
+ event_attribs['sources'] = value.join(',')
+ else # assume plain (single fixture) string
+ event_attribs['sources'] = value.to_s
+ end
else
## todo: add a source location struct to_s or similar (file, line, col)
logger.error "unknown event attrib #{key}; skipping attrib"
end
-
+
end # each key,value
league_id = event_attribs['league_id']
season_id = event_attribs['season_id']
@@ -354,12 +366,15 @@
event.update_attributes!( event_attribs )
end # load_event
+
def load_fixtures_from_string( event_key, text ) # load from string (e.g. passed in via web form)
+ SportDb.lang.lang = SportDb.lang.classify( text )
+
## todo/fix: move code into LineReader e.g. use LineReader.fromString() - why? why not?
reader = StringLineReader.new( text )
load_fixtures_worker( event_key, reader )
@@ -383,10 +398,10 @@
path = "#{include_path}/#{name_real_path}.txt"
logger.info "parsing data '#{name}' (#{path})..."
- SportDb.lang.lang = LangChecker.new.analyze( path )
+ SportDb.lang.lang = SportDb.lang.classify_file( path )
reader = LineReader.new( path )
load_fixtures_worker( event_key, reader )