terminal_game_of_life 0.2.0 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bf5383033cdfa94863a1ffed02d61b746689d927821350042ada2bd3727ac031
4
- data.tar.gz: 9e5c119a3d6b70ef61fc80db8fdc740f3233624e4284da35539fbd1c06e61ba5
3
+ metadata.gz: 63ab48e83b28420afc50509a439c9901cafa84de7acc4d8c53923513b8cc3631
4
+ data.tar.gz: 635c4f76918e9a38b9026f53f296302e78798379632e5df54a524efef4122393
5
5
  SHA512:
6
- metadata.gz: 94b939ec472b19c6d7d38ec0f38ada21d24756c752fba4bb99da96c79c4e2b5a170a46884611ae57eb83d9a6093d81edaa529cfe58feffdee8d7d4d2f609faa4
7
- data.tar.gz: bdc9a52b4f4040c22c72a7583ecb2c0685a031804ad5cb28abadd89465f60a3bd431b3ba8aa424f959e75884c69d2f370865be6d918d52823685a68a8c6eb160
6
+ metadata.gz: 8a3fae98670de950efd9febad455530b4278b98d89155d6157c7c3ceaa99adb01f132b1536cb15ee672b033316601071080d163289dd8e89cc401066fedfedf8
7
+ data.tar.gz: 7f0218b35225633c2e73113080abe520bbc3f509b19e6f5f927a42cdcffd95ef9436926d4a0f978c914bb9d091d651bf2974668d406aa070bbb982e3b14b15e8
@@ -0,0 +1,8 @@
1
+ lib/**/*.rb
2
+
3
+ --readme README.md
4
+ --markup markdown
5
+ --markup-provider redcarpet
6
+ --protected
7
+ --private
8
+ --tag smell:"Code smells"
data/README.md CHANGED
@@ -9,44 +9,50 @@ $ gem install terminal_game_of_life
9
9
 
10
10
  ## Usage
11
11
 
12
- Run `$game-of-life -i https://gitlab.com/a14m --live-cell +`
12
+ ```bash
13
+ $game-of-life -i https://meta.sr.ht/~a14m.keys --live-cell +
14
+ $game-of-life -i /path/to/file.txt --height 35 --width 35
15
+ $game-of-life -s 1337 --delay 250
16
+ ```
13
17
 
14
18
  Check `game-of-life --help` for usage info.
15
19
 
16
20
  ```
21
+ Commands:
17
22
  game-of-life --version, -v # Prints the Game of Life version information
18
23
  game-of-life help [COMMAND] # Describe available commands or one specific command
19
- game-of-life start [OPTIONS] # Start the Game of Life simulations (default command)
24
+ game-of-life start [OPTIONS] # Start the Game of Life simulations
20
25
 
21
26
  Options:
22
27
  -s, [--seed=SEED] # Specify the seed number to use as an initial state (default to random).
23
28
  -i, [--input=VALUE] # Specify the path/URL for the file to use as an initial state. (used instead of seed)
24
- -w, [--width=WIDTH] # Specify the width of generated universe. (default to terminal width)
25
- -h, [--height=HEIGHT] # Specify the hight of generated universe. (default to terminal height)
29
+ [--width=WIDTH] # Specify the width of generated universe. (default to terminal width)
30
+ [--height=HEIGHT] # Specify the hight of generated universe. (default to terminal height)
26
31
  [--dead-cell=CHAR] # Specify the dead-cell representation
27
- # Default:
28
- [--live-cell=CHAR] # Specify the dead-cell representation
32
+ # Default:
33
+ [--live-cell=CHAR] # Specify the live-cell representation
29
34
  # Default: █
30
35
  -d, [--delay=Milli-Seconds] # Specify the introduced delay between each generation
31
36
  # Default: 50
32
37
  ```
33
38
 
34
39
  ## Demo
35
- [![asciicast](https://asciinema.org/a/h7G2EUAXRfwlBVLZjQuXjoTnp.svg)](https://asciinema.org/a/h7G2EUAXRfwlBVLZjQuXjoTnp)
40
+ [![asciicast](https://asciinema.org/a/PsKzaWaNwUq3ZEfrFATqMw0yF.svg)](https://asciinema.org/a/PsKzaWaNwUq3ZEfrFATqMw0yF)
36
41
 
37
42
  ## Development
38
43
 
39
44
  - Clone the repo.
40
45
  - Navigate to the ruby CLI implementation `cd game-of-life/CLI/ruby`.
41
46
  - run `bundle install` to install dependencies.
42
- - run `bundle rake build` to build the gem/CLI into the `pkg` directory.
43
- - run `bundle rake install` to build and install gem/CLI into system gems.
47
+ - you can run `bundle rake build` to build the gem/CLI into the `pkg` directory.
48
+ - you can run `bundle rake install` to build and install gem/CLI into system gems.
49
+ - you can run `bundle exec ./bin/game-of-life` to run the code for development/testing purposes
44
50
 
45
51
  ## Linting
46
52
  Run `bundle exec rubocop`
47
53
 
48
54
  ## Testing
49
- Run `bundle exec rspec` or `bundle exec rake spec`
55
+ Run `bundle exec rspec`
50
56
 
51
57
  ## Documentation
52
58
  Run `bundle exec yard`
@@ -55,7 +61,7 @@ Run `bundle exec yard`
55
61
  - Update the [version](./lib/game_of_live/version.rb) number
56
62
  - Run `bundle install` and commit changes
57
63
  - Update the [CHANGELOG](./CHANGELOG.md)
58
- - Create a git(lab) tag `ruby/v#{version_number}` ex: `ruby/v0.1.1-pre`
64
+ - Create a git tag `ruby/v#{version_number}` ex: `ruby/v0.1.1-pre`
59
65
 
60
66
  The tag will automatically trigger the release workflow after successful build/test
61
67
  and release the changes to [rubygems.org](https://rubygems.org/gems/terminal_game_of_life)
@@ -3,7 +3,6 @@
3
3
 
4
4
  require "game_of_life"
5
5
  require "thor"
6
- require "io/console"
7
6
 
8
7
  class CLI < Thor
9
8
  map %w[-v --version] => :version
@@ -30,35 +29,14 @@ class CLI < Thor
30
29
  desc: "Specify the dead-cell representation"
31
30
 
32
31
  class_option "live-cell", type: :string, banner: :CHAR, default: "\u2588",
33
- desc: "Specify the dead-cell representation"
32
+ desc: "Specify the live-cell representation"
34
33
 
35
34
  class_option "delay", aliases: "-d", type: :numeric, banner: "Milli-Seconds", default: 50,
36
35
  desc: "Specify the introduced delay between each generation"
37
- # rubocop:disable Metrics/AbcSize
38
- # rubocop:disable Metrics/MethodLength
39
36
  def start
40
- max_height = IO.console.winsize[0] - 2
41
- max_width = IO.console.winsize[1]
42
- if options["width"]&.> max_width
43
- fail GameOfLife::Error, "Invalid --width value, must not exceed current terminal width: #{max_width}"
44
- end
45
- if options["height"]&.> max_height
46
- fail GameOfLife::Error, "Invalid --height value, must not exceed current terminal height: #{max_height}"
47
- end
48
-
49
- options_with_console_defaults = {
50
- # Defaults the hight to less then the height of the terminal to allow banner info
51
- # and an extra emtpy line to avoid triggering terminal scroll while flushing
52
- "height" => max_height,
53
- "width" => max_width,
54
- "seed" => rand(100_000),
55
- }.merge(options)
56
-
57
- universe = GameOfLife.generate(options_with_console_defaults)
37
+ universe = GameOfLife.generate(GameOfLife.parsed_options(options))
58
38
  GameOfLife.run(universe)
59
39
  end
60
- # rubocop:enable Metrics/AbcSize
61
- # rubocop:enable Metrics/MethodLength
62
40
 
63
41
  class << self
64
42
  # Allow exit with status 1 on failure
@@ -10,17 +10,19 @@ Gem::Specification.new do |spec|
10
10
 
11
11
  spec.summary = "Game of Life CLI"
12
12
  spec.description = "Conway's game of life implementation as a CLI ruby gem."
13
- spec.homepage = "https://gitlab.com/a14m/game-of-life"
13
+ spec.homepage = "https://git.sr.ht/~a14m/game-of-life/tree/master/CLI/ruby/README.md"
14
14
  spec.license = "MIT"
15
- spec.required_ruby_version = ">= 2.4.0"
15
+ spec.required_ruby_version = ">= 2.5.0"
16
16
 
17
17
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
18
18
  spec.metadata["homepage_uri"] = spec.homepage
19
- spec.metadata["source_code_uri"] = "https://gitlab.com/a14m/game-of-life/-/tree/master/CLI/ruby/"
19
+ spec.metadata["source_code_uri"] = "https://git.sr.ht/~a14m/game-of-life/tree/master/CLI/ruby"
20
+ spec.metadata["documentation_uri"] = "https://rubydoc.info/gems/terminal_game_of_life"
21
+ spec.metadata["changelog_uri"] = "https://git.sr.ht/~a14m/game-of-life/tree/master/CLI/ruby/CHANGELOG.md"
20
22
 
21
23
  spec.executables = ["game-of-life"]
22
24
  spec.require_paths = ["lib"]
23
- spec.files = Dir["README.md", "game_of_life.gemspec", "bin/game-of-life", "lib/**/*.rb"]
25
+ spec.files = Dir["README.md", "game_of_life.gemspec", "bin/game-of-life", "lib/**/*.rb", ".yardopts"]
24
26
 
25
27
  spec.add_dependency "thor", "~> 1.0"
26
28
 
@@ -29,6 +31,10 @@ Gem::Specification.new do |spec|
29
31
  spec.add_development_dependency "rake"
30
32
  spec.add_development_dependency "rspec"
31
33
  spec.add_development_dependency "rubocop"
34
+ spec.add_development_dependency "rubocop-rspec"
35
+ # Code Coverage dependencies
36
+ spec.add_development_dependency "codecov"
37
+ spec.add_development_dependency "simplecov"
32
38
  # Documentation dependencies
33
39
  spec.add_development_dependency "redcarpet"
34
40
  spec.add_development_dependency "yard"
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "io/console"
3
4
  require "game_of_life/version"
4
5
  require "game_of_life/plane"
5
6
  require "game_of_life/universe"
@@ -11,6 +12,58 @@ module GameOfLife
11
12
  class Error < StandardError; end
12
13
 
13
14
  class << self
15
+ # Validate and parse the CLI options and set defaults for the dynamic options.
16
+ # @param options [Hash] CLI options to generate initial conditions
17
+ # @option options [String | nil] "input" path to a local file or URL to open
18
+ # @option options [Numeric | nil] "seed" number to use if no "input" is provided
19
+ # @option options [Numeric] "width" of the universe
20
+ # @option options [Numeric] "height" of the universe
21
+ # @option options [Numeric] "delay" introduced after each cycle
22
+ # @option options [String] "live-cell" representation
23
+ # @option options [String] "dead-cell" representation
24
+ # @smell AbcSize, MethodLenght, Cyclomatic and Perceived Complexity needed for parsing and validating options
25
+ # rubocop:disable Metrics/AbcSize
26
+ # rubocop:disable Metrics/MethodLength
27
+ # rubocop:disable Metrics/CyclomaticComplexity
28
+ # rubocop:disable Metrics/PerceivedComplexity
29
+ # return [Hash] of the parsed options with dynamic defaults based on window size and kernel random
30
+ def parsed_options(options)
31
+ max_height = IO.console.winsize[0] - 2
32
+ max_width = IO.console.winsize[1]
33
+
34
+ if options["delay"].to_i.negative?
35
+ fail GameOfLife::Error, "Invalid --delay value. must be positive value (sadly this is how time works -so far-)"
36
+ end
37
+ if (options["width"]&.< 1) || (options["width"]&.> max_width)
38
+ fail GameOfLife::Error, "Invalid --width value. " \
39
+ "must be between 1 and #{max_width} (current terminal width)"
40
+ end
41
+ if (options["height"]&.< 1) || (options["height"]&.> max_height)
42
+ fail GameOfLife::Error, "Invalid --height value. " \
43
+ "must be between 1 and #{max_height} (current terminal height)"
44
+ end
45
+
46
+ fail GameOfLife::Error, "Invalid --live-cell value. must be a single character" if options["live-cell"].length > 1
47
+
48
+ fail GameOfLife::Error, "Invalid --dead-cell value. must be a single character" if options["dead-cell"].length > 1
49
+
50
+ if options["dead-cell"] == options["live-cell"]
51
+ fail GameOfLife::Error, "Invalid --dead-cell value. must be a different character than --live-cell"
52
+ end
53
+
54
+ {
55
+ # Defaults the hight to less then the height of the terminal to allow banner info
56
+ # and an extra emtpy line to avoid triggering terminal scroll while flushing
57
+ "height" => max_height,
58
+ "width" => max_width,
59
+ "seed" => rand(100_000),
60
+ }.merge(options)
61
+ end
62
+ # rubocop:enable Metrics/AbcSize
63
+ # rubocop:enable Metrics/MethodLength
64
+ # rubocop:enable Metrics/CyclomaticComplexity
65
+ # rubocop:enable Metrics/PerceivedComplexity
66
+
14
67
  # Generate a universe based on the options (from an input file/URI) or using a random/passed seed
15
68
  # This method also sets the Classes/Modules constants for the run defining the options for
16
69
  # Cell (Dead/Live) state representations, and the delay introduced after rendering each universe/generation
@@ -49,9 +102,9 @@ module GameOfLife
49
102
  end
50
103
  end
51
104
 
52
- # Private method to do the terminal screen/scrollback buffer cleaning
105
+ # render method to do the terminal screen/scrollback buffer cleaning
53
106
  # and rendering of the current universe/banner info
54
- # based on the delay configured by the user
107
+ # based on the delay/cell configured by the user
55
108
  def render(universe)
56
109
  puts "\33c\e[3J" # Clears the screen and scrollback buffer.
57
110
  puts universe.to_s
@@ -2,5 +2,5 @@
2
2
 
3
3
  module GameOfLife
4
4
  # Game of life version number
5
- VERSION = "0.2.0"
5
+ VERSION = "1.0.3"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: terminal_game_of_life
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - a14m
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-10 00:00:00.000000000 Z
11
+ date: 2021-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -94,6 +94,48 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: codecov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
97
139
  - !ruby/object:Gem::Dependency
98
140
  name: redcarpet
99
141
  requirement: !ruby/object:Gem::Requirement
@@ -130,6 +172,7 @@ executables:
130
172
  extensions: []
131
173
  extra_rdoc_files: []
132
174
  files:
175
+ - ".yardopts"
133
176
  - README.md
134
177
  - bin/game-of-life
135
178
  - game_of_life.gemspec
@@ -140,14 +183,16 @@ files:
140
183
  - lib/game_of_life/plane.rb
141
184
  - lib/game_of_life/universe.rb
142
185
  - lib/game_of_life/version.rb
143
- homepage: https://gitlab.com/a14m/game-of-life
186
+ homepage: https://git.sr.ht/~a14m/game-of-life/tree/master/CLI/ruby/README.md
144
187
  licenses:
145
188
  - MIT
146
189
  metadata:
147
190
  allowed_push_host: https://rubygems.org
148
- homepage_uri: https://gitlab.com/a14m/game-of-life
149
- source_code_uri: https://gitlab.com/a14m/game-of-life/-/tree/master/CLI/ruby/
150
- post_install_message:
191
+ homepage_uri: https://git.sr.ht/~a14m/game-of-life/tree/master/CLI/ruby/README.md
192
+ source_code_uri: https://git.sr.ht/~a14m/game-of-life/tree/master/CLI/ruby
193
+ documentation_uri: https://rubydoc.info/gems/terminal_game_of_life
194
+ changelog_uri: https://git.sr.ht/~a14m/game-of-life/tree/master/CLI/ruby/CHANGELOG.md
195
+ post_install_message:
151
196
  rdoc_options: []
152
197
  require_paths:
153
198
  - lib
@@ -155,7 +200,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
155
200
  requirements:
156
201
  - - ">="
157
202
  - !ruby/object:Gem::Version
158
- version: 2.4.0
203
+ version: 2.5.0
159
204
  required_rubygems_version: !ruby/object:Gem::Requirement
160
205
  requirements:
161
206
  - - ">="
@@ -163,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
208
  version: '0'
164
209
  requirements: []
165
210
  rubygems_version: 3.1.4
166
- signing_key:
211
+ signing_key:
167
212
  specification_version: 4
168
213
  summary: Game of Life CLI
169
214
  test_files: []