terminal_game_of_life 1.0.0 → 1.0.1

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: b949e4ff807eb374946cc0c2647f9aa5cf3f79b2427cab818b492ecdbb9a3b24
4
- data.tar.gz: b0e82c40b3c53972f52382728281cc2b83219835ffe1ad65c89f9e446beadf02
3
+ metadata.gz: d10a840c6d071548bbd56b1fb2f17a9658c19c086bd47d54446eeaff15644f0a
4
+ data.tar.gz: e310c4bc97030a3499da866a6a388f4b50dc262d7a6e6821af888691570cda54
5
5
  SHA512:
6
- metadata.gz: 96e1fd3c329a3d775a7d332351303c53a2767857ccef421ad372ec8abbebae7bd4f7d07ae2ad23210cd360d889d21fa7ccafc6c9dc08388a6ffb967dd44afa52
7
- data.tar.gz: 8674f279918813b3cf8c4ee1ed9a2d257c48755a3c06e687a2f5f17cdf6707e85509277042e3176d6eaa5e7c69ae143bc5d4e996572a55fa73900c2bc8e9ac1d
6
+ metadata.gz: '085e910813f204a6780bebee121a51dd3a5813f969ccf4a001039d46e7606ad87200f9cac47049e8963894d94fafbdc9331c22260d86c4987dff423ef996143e'
7
+ data.tar.gz: d3bbf008fb39c7b2e2f5858c68fd991fbe998113d4260abda46cac403d21931bff74e3f46a56f657e0c9adb479725fbbf1ef870cb0f782031658132487295577
data/README.md CHANGED
@@ -9,7 +9,11 @@ $ 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://gitlab.com/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
 
@@ -26,7 +30,7 @@ Options:
26
30
  [--height=HEIGHT] # Specify the hight of generated universe. (default to terminal height)
27
31
  [--dead-cell=CHAR] # Specify the dead-cell representation
28
32
  # Default:
29
- [--live-cell=CHAR] # Specify the dead-cell representation
33
+ [--live-cell=CHAR] # Specify the live-cell representation
30
34
  # Default: █
31
35
  -d, [--delay=Milli-Seconds] # Specify the introduced delay between each generation
32
36
  # Default: 50
@@ -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
@@ -31,6 +31,10 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "rake"
32
32
  spec.add_development_dependency "rspec"
33
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"
34
38
  # Documentation dependencies
35
39
  spec.add_development_dependency "redcarpet"
36
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,50 @@ 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
+ {
47
+ # Defaults the hight to less then the height of the terminal to allow banner info
48
+ # and an extra emtpy line to avoid triggering terminal scroll while flushing
49
+ "height" => max_height,
50
+ "width" => max_width,
51
+ "seed" => rand(100_000),
52
+ }.merge(options)
53
+ end
54
+ # rubocop:enable Metrics/AbcSize
55
+ # rubocop:enable Metrics/MethodLength
56
+ # rubocop:enable Metrics/CyclomaticComplexity
57
+ # rubocop:enable Metrics/PerceivedComplexity
58
+
14
59
  # Generate a universe based on the options (from an input file/URI) or using a random/passed seed
15
60
  # This method also sets the Classes/Modules constants for the run defining the options for
16
61
  # Cell (Dead/Live) state representations, and the delay introduced after rendering each universe/generation
@@ -2,5 +2,5 @@
2
2
 
3
3
  module GameOfLife
4
4
  # Game of life version number
5
- VERSION = "1.0.0"
5
+ VERSION = "1.0.1"
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: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - a14m
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-12 00:00:00.000000000 Z
11
+ date: 2020-12-14 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
@@ -165,7 +207,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
207
  - !ruby/object:Gem::Version
166
208
  version: '0'
167
209
  requirements: []
168
- rubygems_version: 3.2.0
210
+ rubygems_version: 3.2.1
169
211
  signing_key:
170
212
  specification_version: 4
171
213
  summary: Game of Life CLI