class Standings::Displayer
Attributes
results[R]
Public Class Methods
new(results)
click to toggle source
# File lib/standings/displayer.rb, line 5 def initialize(results) @results = results end
Public Instance Methods
display_table()
click to toggle source
# File lib/standings/displayer.rb, line 9 def display_table puts dividing_line puts "# GP Pts W D L Team" puts dividing_line results.teams.each do |team| puts template(team) sleep 0.01 end puts dividing_line end
template(team)
click to toggle source
# File lib/standings/displayer.rb, line 22 def template(team) output = "#{(team.position.to_s).ljust(3," ")} " \ "#{team.played.to_s.ljust(3, " ")} " \ "#{team.points.to_s.ljust(5, " ")}" \ "#{team.wins.to_s.ljust(5, " ")}" \ "#{team.draws.to_s.ljust(5, " ")}" \ "#{team.losses.to_s.ljust(5, " ")}" if results.top?(team) output += team.name.green elsif results.middle?(team) output += team.name.light_blue elsif results.bottom?(team) output += team.name.red else output += team.name end end
Private Instance Methods
dividing_line()
click to toggle source
# File lib/standings/displayer.rb, line 44 def dividing_line # draw enough dashes so that teams with long names are still covered # by the dashes. Given a team length integer, add it to 31 # (the length of the static puts statement in #display_table) "-" * (31 + longest_team_name_length) end
longest_team_name_length()
click to toggle source
# File lib/standings/displayer.rb, line 51 def longest_team_name_length results.teams.map {|t| t.name.length }.max end