Skip to content

Instantly share code, notes, and snippets.

@timeout
Created July 2, 2012 15:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timeout/3033942 to your computer and use it in GitHub Desktop.
Save timeout/3033942 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby19
class Team
attr_reader :name
attr_accessor :points, :noGames
def initialize(name)
@name = name
@points = 0.to_f
@total = 0.to_f
@noGames = 0
end
def result(points)
@noGames += 1
@total += points
@points = @total / @noGames
end
def reset
@noGames = 0
@points = 0.to_f
end
end
def points(team1, team2, score1, score2)
if score1 > score2
team1.result(3)
team2.result(0)
elsif score1 == score2
team1.result(2)
team2.result(2)
else
team1.result(0)
team2.result(3)
end
end
def scoreboard(teams)
teams.each do |key, value|
puts "#{value.name}: points: #{value.points}, Games: #{value.noGames}"
end
end
@f = open('1112_bundesliga.txt')
$c = @f.readlines
def get_results(from_rd, to_rd)
@found = false
$c.each do |line|
if line =~ /#{from_rd}:/ and @found == false
@found = true
elsif line =~ /#{to_rd}:/ and @found == true
@found = false
elsif @found == true
puts line.chomp
end
end
end
get_results(10, 13)
@team_names = {
:FCK => '1.FC K\'lautern',
:KOE => '1. FC Koeln',
:FCN => '1.FC Nürnberg',
:LEV => 'B. Leverkusen',
:BVB => 'Bor. Dortmund',
:BMG => 'Bor. M\'gladbach',
:FCA => 'FC Augsburg',
:FCB => 'B. München',
:S04 => 'Schalke 04',
:M05 => 'Mainz 05',
:HSV => 'Hamburger SV',
:H96 => 'Hannover 96',
:BER => 'Hertha BSC',
:SCF => 'SC Freiburg',
:BRE => 'Werder Bremen',
:HOF => '1899 Hoffenheim',
:VFB => 'VfB Stuttgart',
:WOB => 'VfL Wolfsburg'
}
@teams = {}
@team_names.each do |key, name|
@teams[key] = Team.new(name)
end
@teams[:FCK].result(3)
puts "result : #{@teams[:KOE].points} - #{@teams[:KOE].noGames}"
@teams[:FCN].result(3)
puts "result : #{@teams[:FCN].points} - #{@teams[:FCN].noGames}"
@teams[:LEV].result(1)
puts "result : #{@teams[:LEV].points} - #{@teams[:LEV].noGames}"
points(@teams[:FCK], @teams[:LEV], 0, 1)
puts "result : #{@teams[:FCK].points} - #{@teams[:FCK].noGames}"
puts "result : #{@teams[:LEV].points} - #{@teams[:LEV].noGames}"
# print scoreboard
scoreboard(@teams)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment