GemCodebreaker 0.1.6 → 0.1.6.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: d68658435b24026df49116af030e2ed5ef790fdd7975f9c0532fbb1318cbef11
4
- data.tar.gz: e5693bc8fb47255ff1db31912f2c53214e6976cc42b025f62a249381139aad1a
3
+ metadata.gz: 9549d8b7b904ba7a7dd12ba578df792a025341e62943871ebc8a996cae14a015
4
+ data.tar.gz: a74f4a73d55bd84690faec47daae52ab2f3beec1cf6ac648cc663b94936da4a1
5
5
  SHA512:
6
- metadata.gz: c0e3a636cbdc10ec10e12fc548088be337159ffd74f4c732543a695916a0b81ed91fb6bb8a98dfd8c93feb7cc84415ca6e5849c29e34a97c0f5e14444f80afaf
7
- data.tar.gz: 9c083514277ee9eea3ed8997b845bf78a11ee44e4ebccd23ee073b6df7b5e632fb5a1b84eaf07d539d4a654bfb3c832cd937eadc3f44af2ba7432d2b26f16cf1
6
+ metadata.gz: b5ac89139cbdac6d3577732991f26a230a7997057d529d90b4eab31d95a99097a5928bf5a1559fad1847a1ac587de066dc377c86ab55f561188468c58d5c789e
7
+ data.tar.gz: 6c358f040b634d6f16426210f122df3d521cbb886148315ab3de9f8c43a8600c51a28f2fc55c75867210e6d2ee87e11c36edd2257229f22108863ad587842383
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: GemCodebreaker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vasyl
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-07-14 00:00:00.000000000 Z
11
+ date: 2020-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fasterer
@@ -114,37 +114,7 @@ email:
114
114
  executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
- files:
118
- - ".circleci/config.yml"
119
- - ".fasterer.yml"
120
- - ".gitignore"
121
- - ".rspec"
122
- - ".rubocop.yml"
123
- - GemCodebreaker.gemspec
124
- - Gemfile
125
- - Gemfile.lock
126
- - LICENSE.txt
127
- - README.md
128
- - bin/console
129
- - bin/setup
130
- - lib/GemCodebreaker/classes/codemaker.rb
131
- - lib/GemCodebreaker/classes/game.rb
132
- - lib/GemCodebreaker/classes/game_config.rb
133
- - lib/GemCodebreaker/classes/game_statistic.rb
134
- - lib/GemCodebreaker/classes/user.rb
135
- - lib/GemCodebreaker/config/i18n_locales.rb
136
- - lib/GemCodebreaker/errors/incorrect_length_error.rb
137
- - lib/GemCodebreaker/errors/name_length_error.rb
138
- - lib/GemCodebreaker/errors/no_attempts_error.rb
139
- - lib/GemCodebreaker/errors/no_hints_error.rb
140
- - lib/GemCodebreaker/errors/unknow_level_error.rb
141
- - lib/GemCodebreaker/errors/value_range_error.rb
142
- - lib/GemCodebreaker/errors/wrong_class_error.rb
143
- - lib/GemCodebreaker/gem_codebreaker.rb
144
- - lib/GemCodebreaker/modules/game_configurations.rb
145
- - lib/GemCodebreaker/modules/serializer_deserializer.rb
146
- - lib/GemCodebreaker/modules/validator.rb
147
- - lib/GemCodebreaker/version.rb
117
+ files: []
148
118
  homepage: https://github.com/vasivaas/GemCodebreaker
149
119
  licenses:
150
120
  - MIT
@@ -1,67 +0,0 @@
1
- version: 2.1
2
-
3
- executors:
4
- default:
5
- working_directory: ~/codebreaker
6
- description: Gem for game codebreaker
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:
34
- name: fasterer
35
- command: bundle exec fasterer
36
- run_specs:
37
- description: Run specs
38
- steps:
39
- - run:
40
- name: run spec
41
- command: |
42
- mkdir /tmp/test-results
43
- TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
44
- bundle exec rspec --format progress \
45
- --out /tmp/test-results/rspec.xml \
46
- $TEST_FILES
47
-
48
- jobs:
49
- lintering:
50
- executor: default
51
- steps:
52
- - setup_environment
53
- - run_linters
54
- run_specs:
55
- executor: default
56
- steps:
57
- - setup_environment
58
- - run_specs
59
-
60
- workflows:
61
- version: 2
62
- build:
63
- jobs:
64
- - lintering
65
- - run_specs:
66
- requires:
67
- - lintering
@@ -1,21 +0,0 @@
1
- speedups:
2
- rescue_vs_respond_to: true
3
- module_eval: true
4
- shuffle_first_vs_sample: true
5
- for_loop_vs_each: true
6
- each_with_index_vs_while: false
7
- map_flatten_vs_flat_map: true
8
- reverse_each_vs_reverse_each: true
9
- select_first_vs_detect: true
10
- sort_vs_sort_by: true
11
- fetch_with_argument_vs_block: true
12
- keys_each_vs_each_key: true
13
- hash_merge_bang_vs_hash_brackets: true
14
- block_vs_symbol_to_proc: true
15
- proc_call_vs_yield: true
16
- gsub_vs_tr: true
17
- select_last_vs_reverse_detect: true
18
- getter_vs_attr_reader: true
19
- setter_vs_attr_writer: true
20
- exclude_paths:
21
- - 'vendor/**/*.rb'
data/.gitignore DELETED
@@ -1,11 +0,0 @@
1
- /.bundle/
2
- /.yardoc
3
- /_yardoc/
4
- /coverage/
5
- /doc/
6
- /pkg/
7
- /spec/reports/
8
- /tmp/
9
-
10
- .rspec_status
11
- .idea
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
@@ -1,15 +0,0 @@
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']
@@ -1,37 +0,0 @@
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 'i18n', '~> 1.8.3'
32
- spec.add_development_dependency 'rake', '~> 13.0.1'
33
- spec.add_development_dependency 'rspec', '~> 3.7.0'
34
- spec.add_development_dependency 'rubocop', '~> 0.84.0'
35
- spec.add_development_dependency 'rubocop-rspec', '~> 1.41.0'
36
- spec.add_development_dependency 'simplecov', '~> 0.18.5'
37
- end
data/Gemfile DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- source 'https://rubygems.org'
4
- git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
5
-
6
- gemspec
@@ -1,74 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- GemCodebreaker (0.1.5)
5
-
6
- GEM
7
- remote: https://rubygems.org/
8
- specs:
9
- ast (2.4.1)
10
- colorize (0.8.1)
11
- concurrent-ruby (1.1.6)
12
- diff-lcs (1.3)
13
- docile (1.3.2)
14
- fasterer (0.8.3)
15
- colorize (~> 0.7)
16
- ruby_parser (>= 3.14.1)
17
- i18n (1.8.3)
18
- concurrent-ruby (~> 1.0)
19
- parallel (1.19.2)
20
- parser (2.7.1.3)
21
- ast (~> 2.4.0)
22
- rainbow (3.0.0)
23
- rake (13.0.1)
24
- rexml (3.2.4)
25
- rspec (3.7.0)
26
- rspec-core (~> 3.7.0)
27
- rspec-expectations (~> 3.7.0)
28
- rspec-mocks (~> 3.7.0)
29
- rspec-core (3.7.1)
30
- rspec-support (~> 3.7.0)
31
- rspec-expectations (3.7.0)
32
- diff-lcs (>= 1.2.0, < 2.0)
33
- rspec-support (~> 3.7.0)
34
- rspec-mocks (3.7.0)
35
- diff-lcs (>= 1.2.0, < 2.0)
36
- rspec-support (~> 3.7.0)
37
- rspec-support (3.7.1)
38
- rubocop (0.84.0)
39
- parallel (~> 1.10)
40
- parser (>= 2.7.0.1)
41
- rainbow (>= 2.2.2, < 4.0)
42
- rexml
43
- rubocop-ast (>= 0.0.3)
44
- ruby-progressbar (~> 1.7)
45
- unicode-display_width (>= 1.4.0, < 2.0)
46
- rubocop-ast (0.0.3)
47
- parser (>= 2.7.0.1)
48
- rubocop-rspec (1.41.0)
49
- rubocop (>= 0.68.1)
50
- ruby-progressbar (1.10.1)
51
- ruby_parser (3.14.2)
52
- sexp_processor (~> 4.9)
53
- sexp_processor (4.15.0)
54
- simplecov (0.18.5)
55
- docile (~> 1.1)
56
- simplecov-html (~> 0.11)
57
- simplecov-html (0.12.2)
58
- unicode-display_width (1.7.0)
59
-
60
- PLATFORMS
61
- ruby
62
-
63
- DEPENDENCIES
64
- GemCodebreaker!
65
- fasterer (~> 0.8.3)
66
- i18n (~> 1.8.3)
67
- rake (~> 13.0.1)
68
- rspec (~> 3.7.0)
69
- rubocop (~> 0.84.0)
70
- rubocop-rspec (~> 1.41.0)
71
- simplecov (~> 0.18.5)
72
-
73
- BUNDLED WITH
74
- 2.1.4
@@ -1,21 +0,0 @@
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 DELETED
@@ -1,44 +0,0 @@
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).
@@ -1,16 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # frozen_string_literal: true
4
-
5
- require 'bundler/setup'
6
- require 'GemCodebreaker/gem_codebreaker'
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 DELETED
@@ -1,8 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
4
- set -vx
5
-
6
- bundle install
7
-
8
- # Do any other automated setup that you need to do here
@@ -1,42 +0,0 @@
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
@@ -1,85 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GemCodebreaker
4
- # Game class
5
- class Game
6
- LENGTH_OF_SECRET_CODE = 4
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 = (1..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
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
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
@@ -1,19 +0,0 @@
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
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
- @user_attempts = 0
16
- @user_hints = 0
17
- end
18
- end
19
- end
@@ -1,17 +0,0 @@
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
-
8
- def initialize(game)
9
- @user_nickname = game.config.user_nick_name
10
- @difficulty = game.config.difficulty
11
- @attempts_total = game.config.max_attempts
12
- @attempts_used = game.attempts
13
- @hints_total = game.config.max_hints
14
- @hints_used = game.hints
15
- end
16
- end
17
- end
@@ -1,19 +0,0 @@
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
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'i18n'
4
-
5
- I18n.available_locales = %i[en ua]
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GemCodebreaker
4
- # Error class to check the length of user code
5
- class IncorrectLengthError < StandardError
6
- def initialize
7
- super(I18n.t('errors.incorrect_length'))
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GemCodebreaker
4
- # Error class to check user nickname
5
- class NameLengthError < StandardError
6
- def initialize
7
- super(I18n.t('errors.name_length'))
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GemCodebreaker
4
- # Error class to check for attempts
5
- class NoAttemptsError < StandardError
6
- def initialize
7
- super(I18n.t('errors.no_attempts'))
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GemCodebreaker
4
- # Error class to check for hints
5
- class NoHintsError < StandardError
6
- def initialize
7
- super(I18n.t('errors.no_hints'))
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GemCodebreaker
4
- # Error class to check game difficulty
5
- class UnknowLevelError < StandardError
6
- def initialize
7
- super(I18n.t('errors.unknow_level'))
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GemCodebreaker
4
- # Error class to check user code
5
- class ValueRangeError < StandardError
6
- def initialize
7
- super(I18n.t('errors.value_range'))
8
- end
9
- end
10
- end
@@ -1,10 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GemCodebreaker
4
- # Error class to check object class
5
- class WrongClassError < StandardError
6
- def initialize
7
- super(I18n.t('errors.wrong_class'))
8
- end
9
- end
10
- end
@@ -1,23 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'GemCodebreaker/config/i18n_locales'
4
- require 'GemCodebreaker/version'
5
- require 'GemCodebreaker/errors/incorrect_length_error'
6
- require 'GemCodebreaker/errors/name_length_error'
7
- require 'GemCodebreaker/errors/no_attempts_error'
8
- require 'GemCodebreaker/errors/no_hints_error'
9
- require 'GemCodebreaker/errors/unknow_level_error'
10
- require 'GemCodebreaker/errors/value_range_error'
11
- require 'GemCodebreaker/errors/wrong_class_error'
12
- require 'GemCodebreaker/modules/validator'
13
- require 'GemCodebreaker/modules/serializer_deserializer'
14
- require 'GemCodebreaker/modules/game_configurations'
15
- require 'GemCodebreaker/classes/user'
16
- require 'GemCodebreaker/classes/codemaker'
17
- require 'GemCodebreaker/classes/game_config'
18
- require 'GemCodebreaker/classes/game_statistic'
19
- require 'GemCodebreaker/classes/game'
20
-
21
- module GemCodebreaker
22
- class Error < StandardError; end
23
- end
@@ -1,18 +0,0 @@
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
- end
18
- end
@@ -1,26 +0,0 @@
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}")
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
@@ -1,35 +0,0 @@
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
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GemCodebreaker
4
- VERSION = '0.1.6'
5
- end