GemCodebreaker 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.circleci/config.yml +64 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.rubocop.yml +15 -0
- data/GemCodebreaker.gemspec +36 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/bin/console.rb +16 -0
- data/bin/setup +8 -0
- data/lib/GemCodebreaker/classes/codemaker.rb +42 -0
- data/lib/GemCodebreaker/classes/game.rb +85 -0
- data/lib/GemCodebreaker/classes/game_config.rb +20 -0
- data/lib/GemCodebreaker/classes/game_statistic.rb +19 -0
- data/lib/GemCodebreaker/classes/user.rb +19 -0
- data/lib/GemCodebreaker/errors/incorrect_length_error.rb +10 -0
- data/lib/GemCodebreaker/errors/name_length_error.rb +10 -0
- data/lib/GemCodebreaker/errors/no_attempts_error.rb +10 -0
- data/lib/GemCodebreaker/errors/no_hints_error.rb +10 -0
- data/lib/GemCodebreaker/errors/unknow_level_error.rb +10 -0
- data/lib/GemCodebreaker/errors/value_range_error.rb +10 -0
- data/lib/GemCodebreaker/errors/wrong_class_error.rb +10 -0
- data/lib/GemCodebreaker/modules/game_configurations.rb +22 -0
- data/lib/GemCodebreaker/modules/serializer_deserializer.rb +26 -0
- data/lib/GemCodebreaker/modules/validator.rb +35 -0
- data/lib/GemCodebreaker/version.rb +5 -0
- data/lib/gem_codebreaker.rb +11 -0
- data/lib/include_classes.rb +7 -0
- data/lib/include_errors.rb +9 -0
- data/lib/include_modules.rb +5 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2d2dfa9bf68321cf0ace835182a126beeccc97c404d366fb22e6a6980ec7418c
|
4
|
+
data.tar.gz: 50f150bd2712c5ab440b0bc100d6f2148f8b82247d25884bc33368e2eeb95c83
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 06b5ad061b3ef49d02ba0f1c6733245e2ba8bdd0ec70419ea133a18959369de0085a2f84e6cee4bf0fd109bf217335add8c1b55d0cb0a3277d033ac549ae8dc8
|
7
|
+
data.tar.gz: c2c2630ec9f37bcc360384063355e6ff24d1c9d28a8f0ad099b0989e7b32056e29cf5d94590b86a922677040591903ab0954e6e2dcc0462aabcd637e62b3c3ce
|
@@ -0,0 +1,64 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
executors:
|
4
|
+
default:
|
5
|
+
working_directory: ~/codebreaker
|
6
|
+
description: Gem for codebreaker game
|
7
|
+
docker:
|
8
|
+
- image: circleci/ruby:2.7.1
|
9
|
+
|
10
|
+
caches:
|
11
|
+
- &bundle_cache_full v1-codebreaker-{{ checksum "Gemfile.lock" }}
|
12
|
+
- &bundle_cache v1-codebreaker
|
13
|
+
|
14
|
+
commands:
|
15
|
+
setup_environment:
|
16
|
+
steps:
|
17
|
+
- checkout
|
18
|
+
- restore_cache:
|
19
|
+
keys:
|
20
|
+
- *bundle_cache_full
|
21
|
+
- *bundle_cache
|
22
|
+
- run: bundle install --path vendor/bundle
|
23
|
+
- save_cache:
|
24
|
+
paths:
|
25
|
+
- vendor/bundle
|
26
|
+
key: *bundle_cache_full
|
27
|
+
run_linters:
|
28
|
+
description: Start lintering
|
29
|
+
steps:
|
30
|
+
- run:
|
31
|
+
name: rubocop
|
32
|
+
command: bundle exec rubocop
|
33
|
+
run_specs:
|
34
|
+
description: Run specs
|
35
|
+
steps:
|
36
|
+
- run:
|
37
|
+
name: run spec
|
38
|
+
command: |
|
39
|
+
mkdir /tmp/test-results
|
40
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
41
|
+
bundle exec rspec --format progress \
|
42
|
+
--out /tmp/test-results/rspec.xml \
|
43
|
+
$TEST_FILES
|
44
|
+
|
45
|
+
jobs:
|
46
|
+
lintering:
|
47
|
+
executor: default
|
48
|
+
steps:
|
49
|
+
- setup_environment
|
50
|
+
- run_linters
|
51
|
+
run_specs:
|
52
|
+
executor: default
|
53
|
+
steps:
|
54
|
+
- setup_environment
|
55
|
+
- run_specs
|
56
|
+
|
57
|
+
workflows:
|
58
|
+
version: 2
|
59
|
+
build:
|
60
|
+
jobs:
|
61
|
+
- lintering
|
62
|
+
- run_specs:
|
63
|
+
requires:
|
64
|
+
- lintering
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rspec
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 2.7.1
|
6
|
+
NewCops: enable
|
7
|
+
|
8
|
+
Layout/LineLength:
|
9
|
+
Max: 120
|
10
|
+
Metrics/ModuleLength:
|
11
|
+
Max: 270
|
12
|
+
RSpec/MessageSpies:
|
13
|
+
EnforcedStyle: receive
|
14
|
+
Metrics/BlockLength:
|
15
|
+
ExcludedMethods: ['describe', 'context']
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
lib = File.expand_path('lib', __dir__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require_relative 'lib/GemCodebreaker/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'GemCodebreaker'
|
9
|
+
spec.version = GemCodebreaker::VERSION
|
10
|
+
spec.authors = ['Vasyl']
|
11
|
+
spec.email = ['wkichira@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Codebreaker Game'
|
14
|
+
spec.description = 'This gem for Codebreaker Game'
|
15
|
+
spec.homepage = 'https://github.com/vasivaas/GemCodebreaker'
|
16
|
+
spec.license = 'MIT'
|
17
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
|
18
|
+
|
19
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
20
|
+
|
21
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
22
|
+
spec.metadata['source_code_uri'] = 'https://github.com/vasivaas/GemCodebreaker'
|
23
|
+
|
24
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = 'exe'
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ['lib']
|
30
|
+
spec.add_development_dependency 'fasterer', '~> 0.8.3'
|
31
|
+
spec.add_development_dependency 'rake', '~> 13.0.1'
|
32
|
+
spec.add_development_dependency 'rspec', '~> 3.7.0'
|
33
|
+
spec.add_development_dependency 'rubocop', '~> 0.84.0'
|
34
|
+
spec.add_development_dependency 'rubocop-rspec', '~> 1.41.0'
|
35
|
+
spec.add_development_dependency 'simplecov', '~> 0.18.5'
|
36
|
+
end
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Vasyl
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# GemCodebreaker
|
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/GemCodebreaker`. 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
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'GemCodebreaker'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install GemCodebreaker
|
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 tags, 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]/GemCodebreaker. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/GemCodebreaker/blob/master/CODE_OF_CONDUCT.md).
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
## Code of Conduct
|
43
|
+
|
44
|
+
Everyone interacting in the GemCodebreaker project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/GemCodebreaker/blob/master/CODE_OF_CONDUCT.md).
|
data/bin/console.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# !/usr/bin/env ruby
|
4
|
+
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'GemCodebreaker'
|
7
|
+
|
8
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
9
|
+
# with your gem easier. You can also use a different console, if you like.
|
10
|
+
|
11
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
12
|
+
# require "pry"
|
13
|
+
# Pry.start
|
14
|
+
|
15
|
+
require 'irb'
|
16
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GemCodebreaker
|
4
|
+
# Marker class for game
|
5
|
+
class CodeMaker
|
6
|
+
attr_reader :plus_match, :minus_match, :empty_match
|
7
|
+
|
8
|
+
def initialize(game_code, user_code)
|
9
|
+
@game_code = game_code
|
10
|
+
@user_code = user_code
|
11
|
+
@plus_match = 0
|
12
|
+
@minus_match = 0
|
13
|
+
@empty_match = 0
|
14
|
+
end
|
15
|
+
|
16
|
+
def calculate_result_code
|
17
|
+
count_plus_marker
|
18
|
+
count_minus_and_empty_answer
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def count_plus_marker
|
24
|
+
data = @game_code.zip(@user_code)
|
25
|
+
data.delete_if { |game_code_item, user_code_item| @plus_match += 1 if game_code_item == user_code_item }
|
26
|
+
@game_code, @user_code = data.transpose
|
27
|
+
end
|
28
|
+
|
29
|
+
def count_minus_and_empty_answer
|
30
|
+
return if @game_code.nil?
|
31
|
+
|
32
|
+
@game_code.each do |secret_code_item|
|
33
|
+
if @user_code.include?(secret_code_item)
|
34
|
+
@minus_match += 1
|
35
|
+
@user_code.delete(secret_code_item)
|
36
|
+
else
|
37
|
+
@empty_match += 1
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GemCodebreaker
|
4
|
+
# Game class
|
5
|
+
class Game
|
6
|
+
LENGTH_OF_SECRET_CODE = (1..4).freeze
|
7
|
+
DIGIT_RANGE = (1..6).freeze
|
8
|
+
|
9
|
+
include GameConfigurations
|
10
|
+
include Validator
|
11
|
+
attr_reader :attempts, :hints, :secrete_code, :statistic, :matcher_hash
|
12
|
+
attr_accessor :config
|
13
|
+
|
14
|
+
def initialize(user, level)
|
15
|
+
@config = GameConfig.new(user, level.to_sym)
|
16
|
+
@attempts = @config.user_attempts
|
17
|
+
@hints = @config.user_hints
|
18
|
+
@statistic = []
|
19
|
+
end
|
20
|
+
|
21
|
+
def check_configuration
|
22
|
+
validate_game_level(@config.difficulty)
|
23
|
+
end
|
24
|
+
|
25
|
+
def generate_secret_code
|
26
|
+
@secrete_code = LENGTH_OF_SECRET_CODE.map { rand DIGIT_RANGE }
|
27
|
+
end
|
28
|
+
|
29
|
+
def guess_valid?(user_code)
|
30
|
+
validate_string(user_code)
|
31
|
+
validate_guess_length if user_code.length != LENGTH_OF_SECRET_CODE.to_a.length
|
32
|
+
validate_chars_range unless user_code[/\A[1-6]{4}\z/]
|
33
|
+
true
|
34
|
+
end
|
35
|
+
|
36
|
+
def guess_start(input_code)
|
37
|
+
validate_number_of_attempts if @attempts >= @config.max_attempts
|
38
|
+
|
39
|
+
@attempts += 1
|
40
|
+
user_code = convert_string_to_array(input_code)
|
41
|
+
code_marker = CodeMaker.new(@secrete_code, user_code)
|
42
|
+
code_marker.calculate_result_code
|
43
|
+
@matcher_hash = { plus: code_marker.plus_match, minus: code_marker.minus_match, empty: code_marker.empty_match }
|
44
|
+
end
|
45
|
+
|
46
|
+
def win_game?
|
47
|
+
@matcher_hash[:plus] == LENGTH_OF_SECRET_CODE.to_a.last
|
48
|
+
end
|
49
|
+
|
50
|
+
def game_over?
|
51
|
+
(@attempts >= @config.max_attempts) && win_game? == false
|
52
|
+
end
|
53
|
+
|
54
|
+
def hints_used?
|
55
|
+
@hints >= @config.max_hints
|
56
|
+
end
|
57
|
+
|
58
|
+
def hint
|
59
|
+
validate_number_of_hints if hints_used?
|
60
|
+
|
61
|
+
@hints += 1
|
62
|
+
@secrete_code.sample
|
63
|
+
end
|
64
|
+
|
65
|
+
def reset
|
66
|
+
@attempts = 0
|
67
|
+
@hints = 0
|
68
|
+
generate_secret_code
|
69
|
+
end
|
70
|
+
|
71
|
+
def save_user_statistic
|
72
|
+
@statistic << current_user_statistic
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def current_user_statistic
|
78
|
+
GameStatistic.new(self)
|
79
|
+
end
|
80
|
+
|
81
|
+
def convert_string_to_array(user_code)
|
82
|
+
user_code.chars.map(&:to_i)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GemCodebreaker
|
4
|
+
# Configuration class for game
|
5
|
+
class GameConfig
|
6
|
+
include GameConfigurations
|
7
|
+
attr_reader :user_attempts, :user_hints, :difficulty_priority
|
8
|
+
attr_accessor :user_nick_name, :difficulty, :max_attempts, :max_hints
|
9
|
+
|
10
|
+
def initialize(user, level)
|
11
|
+
@user_nick_name = user.nick_name
|
12
|
+
@difficulty = level
|
13
|
+
@max_attempts = GAME_LEVEL[level][:attempts]
|
14
|
+
@max_hints = GAME_LEVEL[level][:hints]
|
15
|
+
@difficulty_priority = GAME_LEVEL_PRIORITY[level]
|
16
|
+
@user_attempts = 0
|
17
|
+
@user_hints = 0
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GemCodebreaker
|
4
|
+
# Game statistic class
|
5
|
+
class GameStatistic
|
6
|
+
attr_reader :user_nickname, :difficulty, :attempts_total, :attempts_used, :hints_total, :hints_used,
|
7
|
+
:difficulty_priority
|
8
|
+
|
9
|
+
def initialize(game)
|
10
|
+
@user_nickname = game.config.user_nick_name
|
11
|
+
@difficulty = game.config.difficulty
|
12
|
+
@attempts_total = game.config.max_attempts
|
13
|
+
@attempts_used = game.attempts
|
14
|
+
@hints_total = game.config.max_hints
|
15
|
+
@hints_used = game.hints
|
16
|
+
@difficulty_priority = game.config.difficulty_priority
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GemCodebreaker
|
4
|
+
# User class for game
|
5
|
+
class User
|
6
|
+
include Validator
|
7
|
+
attr_accessor :nick_name
|
8
|
+
|
9
|
+
def initialize(nick_name)
|
10
|
+
@nick_name = nick_name
|
11
|
+
end
|
12
|
+
|
13
|
+
def nickname_valid?
|
14
|
+
validate_string(@nick_name)
|
15
|
+
validate_nickname_length(@nick_name)
|
16
|
+
true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GemCodebreaker
|
4
|
+
module GameConfigurations
|
5
|
+
GAME_LEVEL = { easy:
|
6
|
+
{ attempts: 15,
|
7
|
+
hints: 2 },
|
8
|
+
medium:
|
9
|
+
{ attempts: 10,
|
10
|
+
hints: 1 },
|
11
|
+
hell:
|
12
|
+
{ attempts: 5,
|
13
|
+
hints: 1 },
|
14
|
+
strong_hell:
|
15
|
+
{ attempts: 1,
|
16
|
+
hints: 0 } }.freeze
|
17
|
+
GAME_LEVEL_PRIORITY = { easy: 4,
|
18
|
+
medium: 3,
|
19
|
+
hell: 2,
|
20
|
+
strong_hell: 1 }.freeze
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GemCodebreaker
|
4
|
+
# Serialize and Deserialize data for game statistic
|
5
|
+
module SerializerDeserializer
|
6
|
+
FILE_NAME = 'game_statistic.yml'
|
7
|
+
STATISTIC_DIR = 'data'
|
8
|
+
STORAGE_PATH = File.expand_path("./#{STATISTIC_DIR}/#{FILE_NAME}", File.dirname(__FILE__))
|
9
|
+
|
10
|
+
def data_dir_get
|
11
|
+
data_directory = File.dirname(STORAGE_PATH)
|
12
|
+
Dir.mkdir(data_directory) unless File.directory?(data_directory)
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_game_statistic
|
16
|
+
File.exist?(STORAGE_PATH) ? YAML.load_file(STORAGE_PATH) : []
|
17
|
+
end
|
18
|
+
|
19
|
+
def save_game_statistic(game_statistic)
|
20
|
+
save_game_stat = game_statistic | load_game_statistic
|
21
|
+
File.open(STORAGE_PATH, 'w') do |file|
|
22
|
+
YAML.dump(save_game_stat, file)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module GemCodebreaker
|
4
|
+
# Validator
|
5
|
+
module Validator
|
6
|
+
def validate_game_level(game_level)
|
7
|
+
level = %i[easy medium hell strong_hell]
|
8
|
+
raise GemCodebreaker::UnknowLevelError unless level.include?(game_level)
|
9
|
+
end
|
10
|
+
|
11
|
+
def validate_number_of_hints
|
12
|
+
raise GemCodebreaker::NoHintsError
|
13
|
+
end
|
14
|
+
|
15
|
+
def validate_number_of_attempts
|
16
|
+
raise GemCodebreaker::NoAttemptsError
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate_string(object)
|
20
|
+
raise GemCodebreaker::WrongClassError unless object.is_a?(String)
|
21
|
+
end
|
22
|
+
|
23
|
+
def validate_guess_length
|
24
|
+
raise GemCodebreaker::IncorrectLengthError
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate_chars_range
|
28
|
+
raise GemCodebreaker::ValueRangeError
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate_nickname_length(nickname)
|
32
|
+
raise GemCodebreaker::NameLengthError if nickname.length < 3 || nickname.length > 20
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'GemCodebreaker/version'
|
4
|
+
require_relative 'include_errors'
|
5
|
+
require_relative 'include_modules'
|
6
|
+
require_relative 'include_classes'
|
7
|
+
|
8
|
+
module GemCodebreaker
|
9
|
+
class Error < StandardError; end
|
10
|
+
# Your code goes here...
|
11
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'GemCodebreaker/classes/user'
|
4
|
+
require_relative 'GemCodebreaker/classes/codemaker'
|
5
|
+
require_relative 'GemCodebreaker/classes/game_config'
|
6
|
+
require_relative 'GemCodebreaker/classes/game_statistic'
|
7
|
+
require_relative 'GemCodebreaker/classes/game'
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'GemCodebreaker/errors/incorrect_length_error'
|
4
|
+
require_relative 'GemCodebreaker/errors/name_length_error'
|
5
|
+
require_relative 'GemCodebreaker/errors/no_attempts_error'
|
6
|
+
require_relative 'GemCodebreaker/errors/no_hints_error'
|
7
|
+
require_relative 'GemCodebreaker/errors/unknow_level_error'
|
8
|
+
require_relative 'GemCodebreaker/errors/value_range_error'
|
9
|
+
require_relative 'GemCodebreaker/errors/wrong_class_error'
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: GemCodebreaker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vasyl
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: fasterer
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.8.3
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.8.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 13.0.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 13.0.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.7.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.7.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.84.0
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.84.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.41.0
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.41.0
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: simplecov
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.18.5
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.18.5
|
97
|
+
description: This gem for Codebreaker Game
|
98
|
+
email:
|
99
|
+
- wkichira@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- ".circleci/config.yml"
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".rubocop.yml"
|
108
|
+
- GemCodebreaker.gemspec
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- bin/console.rb
|
113
|
+
- bin/setup
|
114
|
+
- lib/GemCodebreaker/classes/codemaker.rb
|
115
|
+
- lib/GemCodebreaker/classes/game.rb
|
116
|
+
- lib/GemCodebreaker/classes/game_config.rb
|
117
|
+
- lib/GemCodebreaker/classes/game_statistic.rb
|
118
|
+
- lib/GemCodebreaker/classes/user.rb
|
119
|
+
- lib/GemCodebreaker/errors/incorrect_length_error.rb
|
120
|
+
- lib/GemCodebreaker/errors/name_length_error.rb
|
121
|
+
- lib/GemCodebreaker/errors/no_attempts_error.rb
|
122
|
+
- lib/GemCodebreaker/errors/no_hints_error.rb
|
123
|
+
- lib/GemCodebreaker/errors/unknow_level_error.rb
|
124
|
+
- lib/GemCodebreaker/errors/value_range_error.rb
|
125
|
+
- lib/GemCodebreaker/errors/wrong_class_error.rb
|
126
|
+
- lib/GemCodebreaker/modules/game_configurations.rb
|
127
|
+
- lib/GemCodebreaker/modules/serializer_deserializer.rb
|
128
|
+
- lib/GemCodebreaker/modules/validator.rb
|
129
|
+
- lib/GemCodebreaker/version.rb
|
130
|
+
- lib/gem_codebreaker.rb
|
131
|
+
- lib/include_classes.rb
|
132
|
+
- lib/include_errors.rb
|
133
|
+
- lib/include_modules.rb
|
134
|
+
homepage: https://github.com/vasivaas/GemCodebreaker
|
135
|
+
licenses:
|
136
|
+
- MIT
|
137
|
+
metadata:
|
138
|
+
allowed_push_host: https://rubygems.org
|
139
|
+
homepage_uri: https://github.com/vasivaas/GemCodebreaker
|
140
|
+
source_code_uri: https://github.com/vasivaas/GemCodebreaker
|
141
|
+
post_install_message:
|
142
|
+
rdoc_options: []
|
143
|
+
require_paths:
|
144
|
+
- lib
|
145
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
version: 2.3.0
|
150
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: '0'
|
155
|
+
requirements: []
|
156
|
+
rubygems_version: 3.1.2
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Codebreaker Game
|
160
|
+
test_files: []
|