From e631843c7cefda2ef47361b042daeee16be8a13d Mon Sep 17 00:00:00 2001 From: Geoff Hubbard Date: Thu, 14 Jun 2018 10:57:58 +0100 Subject: [PATCH] Extract dashboard into a class. In order to make the dashboard testable it's useful for it to be its own class. Create a /lib directory. Move the guts of the old dashboard file into a Dashboard class. Move the Game class into /lib. Create a new dashboard.rb that performs identically to the old one but now uses the Dashboard class from /lib. --- dashboard.rb | 34 ++++------------------------------ lib/dashboard.rb | 38 ++++++++++++++++++++++++++++++++++++++ game.rb => lib/game.rb | 0 3 files changed, 42 insertions(+), 30 deletions(-) create mode 100755 lib/dashboard.rb rename game.rb => lib/game.rb (100%) diff --git a/dashboard.rb b/dashboard.rb index b4238b9..5413f73 100755 --- a/dashboard.rb +++ b/dashboard.rb @@ -1,33 +1,7 @@ #!/usr/bin/env ruby -require 'colorize' +require_relative 'lib/dashboard' -dashboard = "".ljust(10) -dashboard += "Test Results".ljust(25) -dashboard += "Rubocop Results".ljust(26) -dashboard += "Time until last run".ljust(25) -dashboard += " Total" -dashboard += "\n\n" - -require_relative 'game' -game = Game.new(teams: ARGV[0].split(",")) - - -for team in game.teams - dashboard += "Team #{team.number}".ljust(10) - dashboard += team.rspec_result.ljust(25).colorize(team.rspec_color) - dashboard += team.rubocop_result.ljust(26).colorize(team.rubocop_color) - dashboard += team.time_result.ljust(25).colorize(:white) - dashboard += team.total_points.green - dashboard += "\n\n" -end - -puts dashboard.bold - -rules = "\n * 20 points if you get 100% of the tests passing" -rules += "\n * 10 points if you make Rubocop happy. Each offense takes one point." -rules += "\n * 10 points if you finish in 10 minutes or less. Each additional minute takes one point." - -puts rules - -# puts String.color_samples +team_numbers = ARGV[0].split(',') +game = Game.new(teams: team_numbers) +puts Dashboard.new(game) diff --git a/lib/dashboard.rb b/lib/dashboard.rb new file mode 100755 index 0000000..b2dee7c --- /dev/null +++ b/lib/dashboard.rb @@ -0,0 +1,38 @@ +#!/usr/bin/env ruby + +require 'colorize' +require_relative 'game' + +class Dashboard + def initialize(game) + @game = game + end + + def to_s + dashboard = "".ljust(10) + dashboard += "Test Results".ljust(25) + dashboard += "Rubocop Results".ljust(26) + dashboard += "Time until last run".ljust(25) + dashboard += " Total" + dashboard += "\n\n" + + game = @game + + + for team in game.teams + dashboard += "Team #{team.number}".ljust(10) + dashboard += team.rspec_result.ljust(25).colorize(team.rspec_color) + dashboard += team.rubocop_result.ljust(26).colorize(team.rubocop_color) + dashboard += team.time_result.ljust(25).colorize(:white) + dashboard += team.total_points.green + dashboard += "\n\n" + end + + + rules = "\n * 20 points if you get 100% of the tests passing" + rules += "\n * 10 points if you make Rubocop happy. Each offense takes one point." + rules += "\n * 10 points if you finish in 10 minutes or less. Each additional minute takes one point." + + dashboard.bold + rules + end +end diff --git a/game.rb b/lib/game.rb similarity index 100% rename from game.rb rename to lib/game.rb