summaryrefslogtreecommitdiffstats
path: root/CLI/ruby
diff options
context:
space:
mode:
authora14m <[email protected]>2020-12-02 14:47:04 +0100
committera14m <[email protected]>2020-12-02 14:51:33 +0100
commit81921690c1c090976f4f31262e8a8e7fb010e2db (patch)
treecab90688144d1c5cdd3e36527763b4032f0e0422 /CLI/ruby
parentbeef1220ecae3d4b3faec49059b131488bc8d016 (diff)
Use x,y coordinates instead of pos_x (and disable rubocop warning)
Diffstat (limited to 'CLI/ruby')
-rw-r--r--CLI/ruby/.rubocop.yml9
-rw-r--r--CLI/ruby/lib/game_of_life/cell.rb20
-rw-r--r--CLI/ruby/lib/game_of_life/generators/input.rb2
-rw-r--r--CLI/ruby/spec/game_of_life/cell_spec.rb8
4 files changed, 23 insertions, 16 deletions
diff --git a/CLI/ruby/.rubocop.yml b/CLI/ruby/.rubocop.yml
index 12f8fd8..88abd76 100644
--- a/CLI/ruby/.rubocop.yml
+++ b/CLI/ruby/.rubocop.yml
@@ -8,6 +8,13 @@ Layout/EmptyLineAfterGuardClause:
Layout/LineLength:
Max: 120
+Metrics/BlockLength:
+ Exclude:
+ - "spec/**/*"
+
+Naming/MethodParameterName:
+ AllowedNames: x, y
+
Style/AccessModifierDeclarations:
EnforcedStyle: inline
@@ -16,7 +23,7 @@ Style/Alias:
Style/BlockDelimiters:
Exclude:
- - 'spec/**/*'
+ - "spec/**/*"
Style/Documentation:
Enabled: false
diff --git a/CLI/ruby/lib/game_of_life/cell.rb b/CLI/ruby/lib/game_of_life/cell.rb
index 3f8fcd4..8997b38 100644
--- a/CLI/ruby/lib/game_of_life/cell.rb
+++ b/CLI/ruby/lib/game_of_life/cell.rb
@@ -5,21 +5,21 @@ module GameOfLife
# Class representing a cell in the GemeOfLife universe
# @!attribute [r] alive
# @return [True | False] the living state of the cell
- # @!attribute [r] pos_x
+ # @!attribute [r] x
# @return [Integer] the X-axis position of the cell in the universe
- # @!attribute [r] pos_y
+ # @!attribute [r] y
# @return [Integer] the Y-axis position of the cell in the universe
class Cell
- attr_reader :alive, :pos_x, :pos_y
+ attr_reader :alive, :x, :y
# Initialize a cell in the game of life universe
# @param alive [True|False] boolean indicating if the cell is considered alive
- # @param pos_x [Integer] the x position on the cyclic universe plane
- # @param pos_y [Integer] the y position on the cyclic universe plane
- def initialize(alive:, pos_x:, pos_y:)
+ # @param x [Integer] the x position on the cyclic universe plane
+ # @param y [Integer] the y position on the cyclic universe plane
+ def initialize(alive:, x:, y:)
@alive = alive
- @pos_x = pos_x
- @pos_y = pos_y
+ @x = x
+ @y = y
end
# Representation of a cell
@@ -69,7 +69,7 @@ module GameOfLife
# @see #survive!
# @see #die!
private def repopulate!
- self.class.new(pos_x: @pos_x, pos_y: @pos_y, alive: true)
+ self.class.new(x: x, y: y, alive: true)
end
# Helper method to define the language used in GameOfLife
@@ -86,7 +86,7 @@ module GameOfLife
# @see #repopulate!
# @see #survive!
private def die!
- dead? ? self : self.class.new(pos_x: @pos_x, pos_y: @pos_y, alive: false)
+ dead? ? self : self.class.new(x: x, y: y, alive: false)
end
end
end
diff --git a/CLI/ruby/lib/game_of_life/generators/input.rb b/CLI/ruby/lib/game_of_life/generators/input.rb
index cbde075..05aab1c 100644
--- a/CLI/ruby/lib/game_of_life/generators/input.rb
+++ b/CLI/ruby/lib/game_of_life/generators/input.rb
@@ -34,7 +34,7 @@ module GameOfLife
universe = GameOfLife::Universe.new(height: height, width: width)
(0...height).each do |i|
(0...width).each do |j|
- cell = { pos_x: j, pos_y: i, alive: parsed_input.fetch(i, nil)&.fetch(j, nil) }
+ cell = { x: j, y: i, alive: parsed_input.fetch(i, nil)&.fetch(j, nil) }
universe[i][j] = ::GameOfLife::Cell.new(cell)
end
end
diff --git a/CLI/ruby/spec/game_of_life/cell_spec.rb b/CLI/ruby/spec/game_of_life/cell_spec.rb
index e2fa7a4..063fd06 100644
--- a/CLI/ruby/spec/game_of_life/cell_spec.rb
+++ b/CLI/ruby/spec/game_of_life/cell_spec.rb
@@ -1,8 +1,8 @@
# frozen_string_literal: true
RSpec.describe GameOfLife::Cell do
- subject(:living_cell) { described_class.new(pos_x: nil, pos_y: nil, alive: true) }
- subject(:dead_cell) { described_class.new(pos_x: nil, pos_y: nil, alive: false) }
+ subject(:living_cell) { described_class.new(x: nil, y: nil, alive: true) }
+ subject(:dead_cell) { described_class.new(x: nil, y: nil, alive: false) }
describe "#to_s" do
before(:all) do
@@ -90,8 +90,8 @@ RSpec.describe GameOfLife::Cell do
describe "#living_neighbors" do
subject(:cell) { [living_cell, dead_cell].sample }
- let(:living_neighbors) { (0...rand(100)).map { described_class.new(pos_x: nil, pos_y: nil, alive: true) } }
- let(:dead_neighbors) { (0...rand(100)).map { described_class.new(pos_x: nil, pos_y: nil, alive: false) } }
+ let(:living_neighbors) { (0...rand(100)).map { described_class.new(x: nil, y: nil, alive: true) } }
+ let(:dead_neighbors) { (0...rand(100)).map { described_class.new(x: nil, y: nil, alive: false) } }
let(:neighbors) { (living_neighbors + dead_neighbors).shuffle }
it "returns the count of living neighbors cells" do