93
95
def parse_ladle_results(raw_results)
94
rounds = Hash.new { |h, k| h[k] = Round.new }
96
# Mapping of round_number => [id1, id2, ...]
97
byes = Hash.new { |h, k| h[k] = [] }
96
rounds = Hash.new { |h, k| h[k] = Round.new }
99
97
raw_results.each_line do |line|
102
100
when /RD(\d+)-team0*(\d+)=(.*)/
103
101
round, id = Integer($1), Integer($2)
104
rounds[round].add_team(id, clean_score($3))
102
team = clean_score($3)
106
rounds[round].add_team(id, team)
105
107
when /RD(\d+)-score0*(\d+)=(.*)/
106
108
round, id = Integer($1), Integer($2)
107
109
score = Integer(clean_score($3)) rescue nil
109
rounds[round].add_score(id, score)
110
rounds[round].add_score(id, score)
115
byes.each do |round, ids|
116
ids.each { |id| rounds[round].remove_id(id) }
118
113
sorted_rounds = rounds.to_a.sort_by { |(round_num, round)| round_num }
119
114
return sorted_rounds.map { |(round_num, round)| round.to_a }