Module: SportDb

Defined in:
lib/sportdb/importers/import.rb,
lib/sportdb/importers.rb,
lib/sportdb/importers/version.rb

Overview

todo/fix: rename to CsvEventImporter or EventImporter !!! returns Event!! todo/fix/check: rename to CsvMatchReader and CsvMatchReader to CsvMatchParser - why? why not?

Defined Under Namespace

Modules: Module Classes: CsvEventImporter, Package

Class Method Summary collapse

Class Method Details

.read_csv(path) ⇒ Object

add convenience shortcut helper



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/sportdb/importers.rb', line 50

def self.read_csv( path )
  if File.directory?( path )          ## if directory assume "unzipped" package

    DirPackage.new( path ).read_csv
  elsif File.file?( path ) && File.extname( path ) == '.zip'   ## check if file is a .zip (archive) file

    ZipPackage.new( path ).read_csv
  else                                ## no package; assume single (standalone) datafile

    ## assume single (free-standing) file

    full_path = File.expand_path( path )   ## resolve/make path absolute

    ## 1) assume basename is the league key

    ## 2) assume last directory is the season key

    league_key = File.basename( full_path, File.extname( full_path ) )  ## get basename WITHOUT extension

    season_key = File.basename( File.dirname( full_path ) )

    event = CsvEventImporter.read( full_path, league: league_key,
                                              season: season_key )

    puts "added #{event.name} - from source >#{path}<"
    puts "  #{event.teams.size} teams"
    puts "  #{event.matches.size} matches"
    puts "  #{event.rounds.size} rounds"
  end
end