Re: Ruby Quiz - Challenge #9 - Tally Up / Calculate the Standings Table for the English Premier League 2018/19 Season - And the Winner is... Liverpool? Manchester City?
Gerald Bauer <[email protected]>
| Newsgroups | gmane.comp.lang.ruby.general |
|---|---|
| Message-ID | <CAAxEZd_p=mn_Zxt2WhjTVjBceNGEBdM2qVtRr8w12TvQuXHhuQ@mail.gmail.com> |
Hello,
Wow. Great tallyup version.You rock (ruby). As always thanks for
posting / sharing.
For reference here's my test answer using the sportdb text library / gem.
def tallyup( matches )
require 'sportdb/text'
# step 1: convert match array to match "struct / named tuple"
matches = matches.map do |match|
team1 = match[0]
score1, score2 = match[1].split('-')
team2 = match[2]
SportDb::Struct::Match.create(
team1: team1,
score1: score1,
score2: score2,
team2: team2
)
end
# step 2: tally up standings
standings = SportDb::Struct::Standings.new
standings.update( matches )
## note: for the black box "magic" see
https://github.com/yorobot/football.csv/blob/master/sportdb-text/lib/sportdb/text/structs/standings.rb#L175
# step 3: convert to array of arrays
recs = []
standings.to_a.each do |l|
recs << [
l.team,
l.played,
l.won,
l.drawn,
l.lost,
l.goals_for,
l.goals_against,
l.pts
]
end
recs
end
Merry Christmas. Happy New Year. Prosit 2019! See you in 2019. Cheers. Prost.
Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-talk>