From f64697a5aede493d52724860856bcbf9f5803169 Mon Sep 17 00:00:00 2001 From: Ahmed AbdelHalim Date: Fri, 30 Jun 2023 16:00:40 +0200 Subject: Update and fix rubocop offenses --- CLI/ruby/Gemfile | 15 +++++++++++++ CLI/ruby/Gemfile.lock | 33 ++++++++++++++++------------ CLI/ruby/game_of_life.gemspec | 14 +----------- CLI/ruby/lib/game_of_life.rb | 6 ++--- CLI/ruby/lib/game_of_life/generators/seed.rb | 2 +- CLI/ruby/spec/game_of_life_spec.rb | 1 - 6 files changed, 39 insertions(+), 32 deletions(-) diff --git a/CLI/ruby/Gemfile b/CLI/ruby/Gemfile index c0c8dc1..465d188 100644 --- a/CLI/ruby/Gemfile +++ b/CLI/ruby/Gemfile @@ -4,3 +4,18 @@ source "https://rubygems.org" # Specify your gem's dependencies in game_of_life.gemspec gemspec + +group :development, :test do + gem "bundler" + gem "pry-byebug" + gem "rake" + gem "rspec" + gem "rubocop" + gem "rubocop-rspec" + # Code Coverage dependencies + gem "json" + gem "simplecov" + # Documentation dependencies + gem "redcarpet" + gem "yard" +end diff --git a/CLI/ruby/Gemfile.lock b/CLI/ruby/Gemfile.lock index c4b5556..0caff5a 100644 --- a/CLI/ruby/Gemfile.lock +++ b/CLI/ruby/Gemfile.lock @@ -13,21 +13,24 @@ GEM diff-lcs (1.4.4) docile (1.3.5) json (2.5.1) + language_server-protocol (3.17.0.3) method_source (1.0.0) - parallel (1.20.1) - parser (3.0.0.0) + parallel (1.23.0) + parser (3.2.2.3) ast (~> 2.4.1) + racc pry (0.13.1) coderay (~> 1.1) method_source (~> 1.0) pry-byebug (3.9.0) byebug (~> 11.0) pry (~> 0.13.0) - rainbow (3.0.0) + racc (1.7.1) + rainbow (3.1.1) rake (13.0.3) redcarpet (3.5.1) - regexp_parser (2.0.3) - rexml (3.2.4) + regexp_parser (2.8.1) + rexml (3.2.5) rspec (3.10.0) rspec-core (~> 3.10.0) rspec-expectations (~> 3.10.0) @@ -41,21 +44,23 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) rspec-support (3.10.2) - rubocop (1.10.0) + rubocop (1.53.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 3.0.0.0) + parser (>= 3.2.2.3) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) - rexml - rubocop-ast (>= 1.2.0, < 2.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.4.1) - parser (>= 2.7.1.5) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.29.0) + parser (>= 3.2.1.0) rubocop-rspec (2.2.0) rubocop (~> 1.0) rubocop-ast (>= 1.1.0) - ruby-progressbar (1.11.0) + ruby-progressbar (1.13.0) simplecov (0.21.2) docile (~> 1.1) simplecov-html (~> 0.11) @@ -63,7 +68,7 @@ GEM simplecov-html (0.12.3) simplecov_json_formatter (0.1.2) thor (1.1.0) - unicode-display_width (2.0.0) + unicode-display_width (2.4.2) yard (0.9.26) PLATFORMS diff --git a/CLI/ruby/game_of_life.gemspec b/CLI/ruby/game_of_life.gemspec index 3cd6bb3..3c7f86b 100644 --- a/CLI/ruby/game_of_life.gemspec +++ b/CLI/ruby/game_of_life.gemspec @@ -19,23 +19,11 @@ Gem::Specification.new do |spec| spec.metadata["source_code_uri"] = "https://git.sr.ht/~a14m/game-of-life/tree/master/CLI/ruby" spec.metadata["documentation_uri"] = "https://rubydoc.info/gems/terminal_game_of_life" spec.metadata["changelog_uri"] = "https://git.sr.ht/~a14m/game-of-life/tree/master/CLI/ruby/CHANGELOG.md" + spec.metadata["rubygems_mfa_required"] = "true" spec.executables = ["game-of-life"] spec.require_paths = ["lib"] spec.files = Dir["README.md", "game_of_life.gemspec", "bin/game-of-life", "lib/**/*.rb", ".yardopts"] spec.add_dependency "thor", "~> 1.0" - - spec.add_development_dependency "bundler" - spec.add_development_dependency "pry-byebug" - spec.add_development_dependency "rake" - spec.add_development_dependency "rspec" - spec.add_development_dependency "rubocop" - spec.add_development_dependency "rubocop-rspec" - # Code Coverage dependencies - spec.add_development_dependency "json" - spec.add_development_dependency "simplecov" - # Documentation dependencies - spec.add_development_dependency "redcarpet" - spec.add_development_dependency "yard" end diff --git a/CLI/ruby/lib/game_of_life.rb b/CLI/ruby/lib/game_of_life.rb index cb122cb..ca9ce5d 100644 --- a/CLI/ruby/lib/game_of_life.rb +++ b/CLI/ruby/lib/game_of_life.rb @@ -36,11 +36,11 @@ module GameOfLife end if (options["width"]&.< 1) || (options["width"]&.> max_width) fail GameOfLife::Error, "Invalid --width value. " \ - "must be between 1 and #{max_width} (current terminal width)" + "must be between 1 and #{max_width} (current terminal width)" end if (options["height"]&.< 1) || (options["height"]&.> max_height) fail GameOfLife::Error, "Invalid --height value. " \ - "must be between 1 and #{max_height} (current terminal height)" + "must be between 1 and #{max_height} (current terminal height)" end fail GameOfLife::Error, "Invalid --live-cell value. must be a single character" if options["live-cell"].length > 1 @@ -111,7 +111,7 @@ module GameOfLife # Ref: https://stackoverflow.com/questions/11023929/using-the-alternate-screen-in-a-bash-script # Ref: https://superuser.com/questions/122911/what-commands-can-i-use-to-reset-and-clear-my-terminal print "\e[?1049h\e[H" - print universe.to_s + print universe print "\n #{BANNER}" sleep(DELAY / 1000.0) end diff --git a/CLI/ruby/lib/game_of_life/generators/seed.rb b/CLI/ruby/lib/game_of_life/generators/seed.rb index 6399945..ba7074b 100644 --- a/CLI/ruby/lib/game_of_life/generators/seed.rb +++ b/CLI/ruby/lib/game_of_life/generators/seed.rb @@ -32,7 +32,7 @@ module GameOfLife # Create a pseudo(stable) random generator from the seed # Generate a sequence of bytes to cover the Game of Life Universe plane # each byte can be unpacked into binary data string (ex. "01101011") - raw = Random.new(seed).bytes(width * height).unpack1("B*").split("").each_slice(width) + raw = Random.new(seed).bytes(width * height).unpack1("B*").chars.each_slice(width) raw.map { |row| row.map { |char| char.eql?("1") } } end diff --git a/CLI/ruby/spec/game_of_life_spec.rb b/CLI/ruby/spec/game_of_life_spec.rb index a0013a6..34570d3 100644 --- a/CLI/ruby/spec/game_of_life_spec.rb +++ b/CLI/ruby/spec/game_of_life_spec.rb @@ -183,7 +183,6 @@ RSpec.describe GameOfLife do stub_const("DELAY", 100.0) expect_any_instance_of(Kernel).to receive(:print).with("\e[?1049h\e[H") expect_any_instance_of(Kernel).to receive(:print).twice - expect(universe).to receive(:to_s) expect_any_instance_of(Kernel).to receive(:sleep) described_class.render(universe) -- cgit v1.2.3