From 3265911ce64d7ee6a7f1ffc55ac3a4d132367604 Mon Sep 17 00:00:00 2001 From: a14m Date: Mon, 14 Dec 2020 13:00:07 +0100 Subject: Refactor the bin script to be simpler without any logic --- CLI/ruby/bin/game-of-life | 26 ++------------------------ 1 file changed, 2 insertions(+), 24 deletions(-) (limited to 'CLI/ruby') diff --git a/CLI/ruby/bin/game-of-life b/CLI/ruby/bin/game-of-life index f49682e..16dc0fa 100755 --- a/CLI/ruby/bin/game-of-life +++ b/CLI/ruby/bin/game-of-life @@ -3,7 +3,6 @@ require "game_of_life" require "thor" -require "io/console" class CLI < Thor map %w[-v --version] => :version @@ -30,35 +29,14 @@ class CLI < Thor desc: "Specify the dead-cell representation" class_option "live-cell", type: :string, banner: :CHAR, default: "\u2588", - desc: "Specify the dead-cell representation" + desc: "Specify the live-cell representation" class_option "delay", aliases: "-d", type: :numeric, banner: "Milli-Seconds", default: 50, desc: "Specify the introduced delay between each generation" - # rubocop:disable Metrics/AbcSize - # rubocop:disable Metrics/MethodLength def start - max_height = IO.console.winsize[0] - 2 - max_width = IO.console.winsize[1] - if options["width"]&.> max_width - fail GameOfLife::Error, "Invalid --width value, must not exceed current terminal width: #{max_width}" - end - if options["height"]&.> max_height - fail GameOfLife::Error, "Invalid --height value, must not exceed current terminal height: #{max_height}" - end - - options_with_console_defaults = { - # Defaults the hight to less then the height of the terminal to allow banner info - # and an extra emtpy line to avoid triggering terminal scroll while flushing - "height" => max_height, - "width" => max_width, - "seed" => rand(100_000), - }.merge(options) - - universe = GameOfLife.generate(options_with_console_defaults) + universe = GameOfLife.generate(GameOfLife.parsed_options(options)) GameOfLife.run(universe) end - # rubocop:enable Metrics/AbcSize - # rubocop:enable Metrics/MethodLength class << self # Allow exit with status 1 on failure -- cgit v1.2.3