Sha256: 8df8d301c4a57ff8c7a90ea65d7ac5c8029808c6e4b831524201dfa96df990c6

Contents?: true

Size: 1.14 KB

Versions: 20

Compression:

Stored size: 1.14 KB

Contents

# encoding: utf-8


module SportDb
  module Import

class LeagueReader

def self.read( path )
  txt = File.open( path, 'r:utf-8' ).read
  parse( txt )
end



SEASON_REGEX = /\[
                (?<season>
                   \d{4}
                   (-\d{2,4})?
                )
               \]/x

def self.parse( txt )
  hash = {}
  season = '*'   ## use '*' for default/latest season

  txt.each_line do |line|
    line = line.strip

    next if line.empty?
    next if line.start_with?( '#' )   ## skip comments too

    ## strip inline comments too
    line = line.sub( /#.*/, '' ).strip

    pp line


    if (m=line.match( SEASON_REGEX ))
        season = m[:season]
    else
      key_line, values_line = line.split( '=>' )
      values  = values_line.split( ',' )

      ## remove leading and trailing spaces
      key_line = key_line.strip
      values = values.map { |value| value.strip }
      pp values

      league_key      = key_line
      league_basename = values[0]

      hash[season] ||= {}
      hash[season][league_key] = league_basename
    end
  end
  hash
end # method read

end ## class LeagueReader



end ## module Import
end ## module SportDb

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
sportdb-config-0.7.1 lib/sportdb/config/league_reader.rb
sportdb-config-0.7.0 lib/sportdb/config/league_reader.rb
sportdb-config-0.6.0 lib/sportdb/config/league_reader.rb
sportdb-config-0.5.3 lib/sportdb/config/league_reader.rb
sportdb-config-0.5.2 lib/sportdb/config/league_reader.rb
sportdb-config-0.5.1 lib/sportdb/config/league_reader.rb
sportdb-config-0.5.0 lib/sportdb/config/league_reader.rb
sportdb-config-0.4.0 lib/sportdb/config/league_reader.rb
sportdb-config-0.3.6 lib/sportdb/config/league_reader.rb
sportdb-config-0.3.5 lib/sportdb/config/league_reader.rb
sportdb-config-0.3.4 lib/sportdb/config/league_reader.rb
sportdb-config-0.3.3 lib/sportdb/config/league_reader.rb
sportdb-config-0.3.2 lib/sportdb/config/league_reader.rb
sportdb-config-0.3.1 lib/sportdb/config/league_reader.rb
sportdb-config-0.3.0 lib/sportdb/config/league_reader.rb
sportdb-config-0.2.3 lib/sportdb/config/league_reader.rb
sportdb-config-0.2.2 lib/sportdb/config/league_reader.rb
sportdb-config-0.2.1 lib/sportdb/config/league_reader.rb
sportdb-config-0.2.0 lib/sportdb/config/league_reader.rb
sportdb-config-0.1.0 lib/sportdb/config/league_reader.rb