Module: Datasets

Defined in:
lib/football-timezones/datasets.rb

Class Method Summary collapse

Class Method Details

.parse(txt) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/football-timezones/datasets.rb', line 25

def self.parse( txt )
    ### split args in datasets with leagues and seasons
    datasets = []
    recs = parse_csv( txt )
    recs.each do |rec|
        key = rec['league'].downcase
        datasets << [key, []]

        seasons_str = rec['seasons']
        seasons = seasons_str.split( /[ ]+/ )

        seasons.each do |season_str|
            ## note - add support for ranges e.g. 2001/02..2010/11
            if season_str.index( '..' )
                    fst,snd = season_str.split( '..' )
                    # pp [fst,snd]
                    fst = Season.parse( fst )
                    snd = Season.parse( snd )
                    if fst < snd && fst.year? == snd.year?
                        datasets[-1][1] += (fst..snd).to_a
                    else
                       raise ArgumentError, "parse error - invalid season range >#{str}<, 1) two seasons required, 2) first < second, 3) same (year/academic) type"
                    end
            else
               season = Season.parse( season_str )  ## check season
               datasets[-1][1] << season
            end
        end
    end
    datasets
end

.parse_args(args) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/football-timezones/datasets.rb', line 4

def self.parse_args( args )
    ### split args in datasets with leagues and seasons
    datasets = []
    args.each do |arg|
       if arg =~ %r{^[0-9/-]+$}   ##  season
           if datasets.empty?
             puts "!! ERROR - league required before season arg; sorry"
             exit 1
           end

           season = Season.parse( arg )  ## check season
           datasets[-1][1] << season
       else ## assume league key
           key = arg.downcase
           datasets << [key, []]
       end
    end
    datasets
end

.read(path) ⇒ Object



58
59
60
# File 'lib/football-timezones/datasets.rb', line 58

def self.read( path )
    parse( read_text( path ))
end