codebreaker_vv 0.2.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f40670adaae848b6cc6c8af0a96235c58516c595ba21e3651eb71a8b6da1e237
4
- data.tar.gz: 4ebfb0a1574eeb5443c7ed72c007d30aa3959a78caf2254d407b1bf7ed70180f
3
+ metadata.gz: 77eb940969009562c9d6490b4cceec06233b79d01fadf14ddd20cc23db834b3e
4
+ data.tar.gz: 9b8bd99eab675c16e6a91989d239fbcfa6aab90769a43e33a1fffaed386208d9
5
5
  SHA512:
6
- metadata.gz: bb93ff2deb1d5a86ca008d7dbc22e86b714fdb0c075b26d910b5023d89cc3e6f846ac89e1230065a9f9273d43bff324c7b63d8b3b0a44842dd84ff3da7217b00
7
- data.tar.gz: 3e0920396bbd6f37c0ea75ac05fd61a7d7e9861494bbdd69d5fbc4680bf4c4de7108a982cb5c94e2bdb219ba577ee1e1c22ef8f68572624d11657ac36d8d72b4
6
+ metadata.gz: a4fcefb21e16484ad27714ecca6fd32a4832661a295a909b1f805f70674a46ca688541cffff804be79fe09a79660b38439db6db033224b8fadc0bf5af3ba9f6b
7
+ data.tar.gz: 8d98d3eef5524add83d4875fd11d2beb126cf9b5890e4b481d85ecff49e41d0a2c295ad77265ef2ff7208f06224b62e30f9a702bb6b0f5b7517ee46c41786ea7
data/.rubocop.yml CHANGED
@@ -6,3 +6,14 @@ Style/FrozenStringLiteralComment:
6
6
 
7
7
  Metrics/LineLength:
8
8
  Max: 120
9
+ Exclude:
10
+ - 'Rakefile'
11
+ - '**/*.rake'
12
+ - 'spec/**/*.rb'
13
+ - '*.gemspec'
14
+
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - 'Rakefile'
18
+ - '**/*.rake'
19
+ - 'spec/**/*.rb'
data/Gemfile CHANGED
@@ -2,9 +2,3 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in codebreaker.gemspec
4
4
  gemspec
5
-
6
- gem 'rake', '~> 13.0'
7
-
8
- gem 'rspec', '~> 3.0'
9
-
10
- gem 'simplecov'
data/Gemfile.lock CHANGED
@@ -1,9 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- codebreaker_vv (0.1.0)
4
+ codebreaker_vv (0.2.0)
5
5
  fasterer (~> 0.9.0)
6
- pry (~> 0.14.1)
6
+ rspec
7
7
  rubocop (~> 1.21)
8
8
  simplecov (~> 0.21.2)
9
9
 
@@ -11,7 +11,6 @@ GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
13
  ast (2.4.2)
14
- coderay (1.1.3)
15
14
  colorize (0.8.1)
16
15
  diff-lcs (1.5.0)
17
16
  docile (1.4.0)
@@ -19,15 +18,10 @@ GEM
19
18
  colorize (~> 0.7)
20
19
  ruby_parser (>= 3.14.1)
21
20
  json (2.6.2)
22
- method_source (1.0.0)
23
21
  parallel (1.22.1)
24
22
  parser (3.1.2.1)
25
23
  ast (~> 2.4.1)
26
- pry (0.14.1)
27
- coderay (~> 1.1)
28
- method_source (~> 1.0)
29
24
  rainbow (3.1.1)
30
- rake (13.0.6)
31
25
  regexp_parser (2.5.0)
32
26
  rexml (3.2.5)
33
27
  rspec (3.11.0)
@@ -72,9 +66,6 @@ PLATFORMS
72
66
 
73
67
  DEPENDENCIES
74
68
  codebreaker_vv!
75
- rake (~> 13.0)
76
- rspec (~> 3.0)
77
- simplecov
78
69
 
79
70
  BUNDLED WITH
80
71
  2.3.7
data/README.md CHANGED
@@ -1,35 +1,13 @@
1
- # Codebreaker
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/codebreaker`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
1
+ # Codebreaker_vv
6
2
 
7
3
  ## Installation
8
4
 
9
5
  Add this line to your application's Gemfile:
10
6
 
11
7
  ```ruby
12
- gem 'codebreaker'
8
+ gem 'codebreaker_vv'
13
9
  ```
14
10
 
15
11
  And then execute:
16
12
 
17
13
  $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install codebreaker
22
-
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
-
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/codebreaker.
data/codebreaker.gemspec CHANGED
@@ -1,4 +1,5 @@
1
1
  require_relative 'lib/codebreaker/version'
2
+ require_relative 'lib/src/autoloader'
2
3
 
3
4
  Gem::Specification.new do |spec|
4
5
  spec.name = 'codebreaker_vv'
@@ -7,7 +8,7 @@ Gem::Specification.new do |spec|
7
8
  spec.email = ['valerii.radzhabov@rubygarage.org']
8
9
 
9
10
  spec.summary = 'Codebreaker game'
10
- spec.description = 'This awesome gem can create a secret code and a lot of other beautyful things!'
11
+ spec.description = 'This awesome gem can create a secret code and a lot of other beautiful things!'
11
12
  spec.homepage = 'https://rubygems.org/gems/codebreaker_vv'
12
13
  spec.required_ruby_version = '>= 3.1'
13
14
 
@@ -30,7 +31,7 @@ Gem::Specification.new do |spec|
30
31
 
31
32
  # Uncomment to register a new dependency of your gem
32
33
  spec.add_dependency 'fasterer', '~> 0.9.0'
33
- spec.add_dependency 'pry', '~> 0.14.1'
34
+ spec.add_dependency 'rspec'
34
35
  spec.add_dependency 'rubocop', '~> 1.21'
35
36
  spec.add_dependency 'simplecov', '~> 0.21.2'
36
37
 
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
- module Codebreaker
4
- VERSION = '0.2.0'
1
+ class Codebreaker
2
+ VERSION = '1.0.0'.freeze
5
3
  end
data/lib/codebreaker.rb CHANGED
@@ -1,77 +1,70 @@
1
- # require_relative 'codebreaker/version'
2
1
  require_relative 'src/autoloader'
3
2
 
4
- module Codebreaker
5
- class Error < StandardError; end
3
+ class Codebreaker
4
+ attr_reader :secret_code, :attempts, :hints
6
5
 
7
- class << self
8
- attr_reader :secret_code, :attempts, :hints
6
+ def initialize
7
+ @data_base_manager = DataBaseManager.new
8
+ end
9
9
 
10
- def start_game(difficulty, player_name)
11
- @total_attempts = 0
12
- @total_hints = 1
13
- @difficulty = difficulty
14
- @player_name = player_name
15
- init_difficulty_stats(difficulty)
16
- @hints = @total_hints
17
- @attempts = @total_attempts
18
- generate_secret_code
19
- end
10
+ def start_game(difficulty, player_name)
11
+ @difficulty = difficulty
12
+ @player_name = player_name
13
+ init_difficulty_stats(difficulty)
14
+ @hints = @total_hints
15
+ @attempts = @total_attempts
16
+ generate_secret_code
17
+ end
20
18
 
21
- def check_code_and_give_result(user_code)
22
- answer = @verifier.verify_user_code(user_code)
23
- @attempts -= 1
19
+ def check_code_and_give_result(user_code)
20
+ answer = @verifier.verify_user_code(user_code)
21
+ @attempts -= 1
24
22
 
25
- if answer == '++++'
26
- "#{answer} #{Locale::PLAYER_WIN}"
27
- elsif @attempts <= 0
28
- "#{answer} #{Locale::PLAYER_LOSE}"
29
- else
30
- answer
31
- end
23
+ if answer == '++++'
24
+ "#{answer} #{Locale::PLAYER_WIN}"
25
+ elsif @attempts <= 0
26
+ "#{answer} #{Locale::PLAYER_LOSE}"
27
+ else
28
+ answer
32
29
  end
30
+ end
33
31
 
34
- def give_hint
35
- if @hints <= 0
36
- Locale::NO_MORE_HINTS_AVAILABLE
37
- else
38
- @hints -= 1
39
- hint = @code_for_hints.sample
40
- @code_for_hints.delete_at(@code_for_hints.index(hint))
41
- hint
42
- end
32
+ def give_hint
33
+ if @hints <= 0
34
+ Locale::NO_MORE_HINTS_AVAILABLE
35
+ else
36
+ @hints -= 1
37
+ hint = @code_for_hints.sample
38
+ @code_for_hints.delete_at(@code_for_hints.index(hint))
39
+ hint
43
40
  end
41
+ end
44
42
 
45
- def save_game_result
46
- attempts_used = @total_attempts - @attempts
47
- hints_used = @total_hints - @hints
48
- DataBaseManager.instance.save_game_results([@player_name, @difficulty,
49
- @total_attempts, attempts_used,
50
- @total_hints, hints_used])
51
- end
43
+ def save_game_result
44
+ attempts_used = @total_attempts - @attempts
45
+ hints_used = @total_hints - @hints
46
+ @data_base_manager.save_game_results([@player_name, @difficulty,
47
+ @total_attempts, attempts_used,
48
+ @total_hints, hints_used])
49
+ end
52
50
 
53
- def load_game_results
54
- DataBaseManager.instance.load_game_results
55
- end
51
+ def load_game_results
52
+ @data_base_manager.load_game_results
53
+ end
56
54
 
57
- private
55
+ private
58
56
 
59
- def init_difficulty_stats(difficulty)
60
- case difficulty
61
- when 0
62
- @total_attempts = 15
63
- @total_hints = 2
64
- when 1
65
- @total_attempts = 10
66
- else
67
- @total_attempts = 5
68
- end
69
- end
57
+ def init_difficulty_stats(difficulty)
58
+ @total_attempts, @total_hints = case difficulty
59
+ when 0 then [15, 2]
60
+ when 1 then [10, 1]
61
+ else [5, 1]
62
+ end
63
+ end
70
64
 
71
- def generate_secret_code
72
- @secret_code = Factory.new.new_secret_code
73
- @verifier = CodeVerifier.new(@secret_code)
74
- @code_for_hints = @secret_code.clone
75
- end
65
+ def generate_secret_code
66
+ @secret_code = Factory.new_secret_code
67
+ @verifier = CodeVerifier.new(@secret_code)
68
+ @code_for_hints = @secret_code.clone
76
69
  end
77
70
  end
@@ -1,7 +1,8 @@
1
1
  require_relative '../codebreaker/version'
2
+ require_relative '../codebreaker'
2
3
  require_relative 'code_verifier'
3
4
  require_relative 'factory'
4
5
  require_relative 'config/locale'
5
6
  require_relative 'data_base_manager'
6
- require 'pry'
7
+ require 'singleton'
7
8
  require 'yaml'
@@ -1,13 +1,7 @@
1
1
  class DataBaseManager
2
- @instance = new
3
- private_class_method :new
4
- class << self
5
- attr_reader :instance
6
- end
7
-
8
2
  def save_game_results(attributes)
9
3
  data = { name: attributes[0], difficulty: attributes[1], attempts_total: attributes[2],
10
- attempts_used: attributes[3], hints_total: attributes[4], hints_used: attributes[4] }
4
+ attempts_used: attributes[3], hints_total: attributes[4], hints_used: attributes[5] }
11
5
  Dir.mkdir('lib/db') unless Dir.exist?('lib/db')
12
6
  File.open('lib/db/codebreaker_db.yml', 'a') { |file| file.puts(data.to_yaml) }
13
7
  end
data/lib/src/factory.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class Factory
2
- def new_secret_code
2
+ def self.new_secret_code
3
3
  secret_code = []
4
4
 
5
5
  4.times do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreaker_vv
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valerii
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-12 00:00:00.000000000 Z
11
+ date: 2022-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fasterer
@@ -25,19 +25,19 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.9.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: pry
28
+ name: rspec
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: 0.14.1
33
+ version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: 0.14.1
40
+ version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rubocop
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +66,7 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: 0.21.2
69
- description: This awesome gem can create a secret code and a lot of other beautyful
69
+ description: This awesome gem can create a secret code and a lot of other beautiful
70
70
  things!
71
71
  email:
72
72
  - valerii.radzhabov@rubygarage.org
@@ -75,8 +75,6 @@ extensions: []
75
75
  extra_rdoc_files: []
76
76
  files:
77
77
  - ".fasterer.yml"
78
- - ".idea/.gitignore"
79
- - ".idea/codebreaker.iml"
80
78
  - ".rspec"
81
79
  - ".rubocop.yml"
82
80
  - ".ruby-version"
data/.idea/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- # Default ignored files
2
- /shelf/
3
- /workspace.xml
4
- # Editor-based HTTP Client requests
5
- /httpRequests/
6
- # Datasource local storage ignored files
7
- /dataSources/
8
- /dataSources.local.xml
@@ -1,46 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="RUBY_MODULE" version="4">
3
- <component name="ModuleRunConfigurationManager">
4
- <shared />
5
- </component>
6
- <component name="NewModuleRootManager">
7
- <content url="file://$MODULE_DIR$">
8
- <sourceFolder url="file://$MODULE_DIR$/features" isTestSource="true" />
9
- <sourceFolder url="file://$MODULE_DIR$/spec" isTestSource="true" />
10
- <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
11
- </content>
12
- <orderEntry type="inheritedJdk" />
13
- <orderEntry type="sourceFolder" forTests="false" />
14
- <orderEntry type="library" scope="PROVIDED" name="ast (v2.4.2, rbenv: 3.1.2) [gem]" level="application" />
15
- <orderEntry type="library" scope="PROVIDED" name="bundler (v2.3.7, rbenv: 3.1.2) [gem]" level="application" />
16
- <orderEntry type="library" scope="PROVIDED" name="coderay (v1.1.3, rbenv: 3.1.2) [gem]" level="application" />
17
- <orderEntry type="library" scope="PROVIDED" name="colorize (v0.8.1, rbenv: 3.1.2) [gem]" level="application" />
18
- <orderEntry type="library" scope="PROVIDED" name="diff-lcs (v1.5.0, rbenv: 3.1.2) [gem]" level="application" />
19
- <orderEntry type="library" scope="PROVIDED" name="docile (v1.4.0, rbenv: 3.1.2) [gem]" level="application" />
20
- <orderEntry type="library" scope="PROVIDED" name="fasterer (v0.9.0, rbenv: 3.1.2) [gem]" level="application" />
21
- <orderEntry type="library" scope="PROVIDED" name="json (v2.6.2, rbenv: 3.1.2) [gem]" level="application" />
22
- <orderEntry type="library" scope="PROVIDED" name="method_source (v1.0.0, rbenv: 3.1.2) [gem]" level="application" />
23
- <orderEntry type="library" scope="PROVIDED" name="parallel (v1.22.1, rbenv: 3.1.2) [gem]" level="application" />
24
- <orderEntry type="library" scope="PROVIDED" name="parser (v3.1.2.1, rbenv: 3.1.2) [gem]" level="application" />
25
- <orderEntry type="library" scope="PROVIDED" name="pry (v0.14.1, rbenv: 3.1.2) [gem]" level="application" />
26
- <orderEntry type="library" scope="PROVIDED" name="rainbow (v3.1.1, rbenv: 3.1.2) [gem]" level="application" />
27
- <orderEntry type="library" scope="PROVIDED" name="rake (v13.0.6, rbenv: 3.1.2) [gem]" level="application" />
28
- <orderEntry type="library" scope="PROVIDED" name="rbs (v2.1.0, rbenv: 3.1.2) [gem]" level="application" />
29
- <orderEntry type="library" scope="PROVIDED" name="regexp_parser (v2.5.0, rbenv: 3.1.2) [gem]" level="application" />
30
- <orderEntry type="library" scope="PROVIDED" name="rexml (v3.2.5, rbenv: 3.1.2) [gem]" level="application" />
31
- <orderEntry type="library" scope="PROVIDED" name="rspec (v3.11.0, rbenv: 3.1.2) [gem]" level="application" />
32
- <orderEntry type="library" scope="PROVIDED" name="rspec-core (v3.11.0, rbenv: 3.1.2) [gem]" level="application" />
33
- <orderEntry type="library" scope="PROVIDED" name="rspec-expectations (v3.11.0, rbenv: 3.1.2) [gem]" level="application" />
34
- <orderEntry type="library" scope="PROVIDED" name="rspec-mocks (v3.11.1, rbenv: 3.1.2) [gem]" level="application" />
35
- <orderEntry type="library" scope="PROVIDED" name="rspec-support (v3.11.0, rbenv: 3.1.2) [gem]" level="application" />
36
- <orderEntry type="library" scope="PROVIDED" name="rubocop (v1.36.0, rbenv: 3.1.2) [gem]" level="application" />
37
- <orderEntry type="library" scope="PROVIDED" name="rubocop-ast (v1.21.0, rbenv: 3.1.2) [gem]" level="application" />
38
- <orderEntry type="library" scope="PROVIDED" name="ruby-progressbar (v1.11.0, rbenv: 3.1.2) [gem]" level="application" />
39
- <orderEntry type="library" scope="PROVIDED" name="ruby_parser (v3.19.1, rbenv: 3.1.2) [gem]" level="application" />
40
- <orderEntry type="library" scope="PROVIDED" name="sexp_processor (v4.16.1, rbenv: 3.1.2) [gem]" level="application" />
41
- <orderEntry type="library" scope="PROVIDED" name="simplecov (v0.21.2, rbenv: 3.1.2) [gem]" level="application" />
42
- <orderEntry type="library" scope="PROVIDED" name="simplecov-html (v0.12.3, rbenv: 3.1.2) [gem]" level="application" />
43
- <orderEntry type="library" scope="PROVIDED" name="simplecov_json_formatter (v0.1.4, rbenv: 3.1.2) [gem]" level="application" />
44
- <orderEntry type="library" scope="PROVIDED" name="unicode-display_width (v2.2.0, rbenv: 3.1.2) [gem]" level="application" />
45
- </component>
46
- </module>