codebreaker_kosinskiy 0.1.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 242cb2b03eac9c28f40137c33167ce45f9eeac6d1e8cfe54a37f33e759f25e58
4
+ data.tar.gz: c55c2eb97d213d93d2cbd102e98468527df8f74383553493794f8fa07ba7603a
5
+ SHA512:
6
+ metadata.gz: aea4f45508822be73a61f9d75c5c65254f185105e64df51c60db253b8e6566ba2b13f2e0ec755e17fd2daf1540536f42c1ebeed60ebce9496210fb8b2816650b
7
+ data.tar.gz: 4d96dc4ce6e810e740a2e7f78cab59f61222aaf819dfd2b0869d3e751bd84a4638f65bbaa43aff5b5ae364e1e3c8ba14813d23f0dd77142168f95ddf33d03e72
@@ -0,0 +1,61 @@
1
+ version: 2.1
2
+
3
+ executors:
4
+ default:
5
+ working_directory: ~/repo
6
+ description: The official CircleCi Ruby Docker image
7
+ docker:
8
+ - image: circleci/ruby:2.7.0
9
+
10
+ caches:
11
+ - &bundle_cache_full v2-repo-{{ checksum "Gemfile.lock" }}
12
+ - &bundle_cache v2-repo-
13
+
14
+ commands:
15
+ defaults:
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
+ key: *bundle_cache_full
25
+ paths:
26
+ - vendor/bundle
27
+ run_linters:
28
+ description: command to start run_linters
29
+ steps:
30
+ - run:
31
+ name: rubocop
32
+ command: bundle exec rubocop --require rubocop-rspec
33
+ - run:
34
+ name: fasterer
35
+ command: bundle exec fasterer
36
+ run_specs:
37
+ steps:
38
+ - run:
39
+ name: run_specs
40
+ command: bundle exec rspec --format progress spec
41
+
42
+ jobs:
43
+ lintering:
44
+ executor: default
45
+ steps:
46
+ - defaults
47
+ - run_linters
48
+ run_specs:
49
+ executor: default
50
+ steps:
51
+ - defaults
52
+ - run_specs
53
+
54
+ workflows:
55
+ version: 2.1
56
+ build:
57
+ jobs:
58
+ - lintering
59
+ - run_specs:
60
+ requires:
61
+ - lintering
@@ -0,0 +1,21 @@
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'
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ codebreaker-0.1.0.gem
data/.rspec ADDED
@@ -0,0 +1,4 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
4
+ --order random
@@ -0,0 +1,9 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ Style/Documentation:
4
+ Enabled: false
5
+ Style/FrozenStringLiteralComment:
6
+ Enabled: false
7
+ Metrics/BlockLength:
8
+ Exclude:
9
+ - 'spec/**/*.rb'
@@ -0,0 +1 @@
1
+ 2.7.0
@@ -0,0 +1,6 @@
1
+ ---
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.7.0
6
+ before_install: gem install bundler -v 2.1.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at kosinskiy.andrey@ukr.net. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in codebreaker.gemspec
4
+ gemspec
@@ -0,0 +1,73 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ codebreaker_kosinskiy (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ast (2.4.1)
10
+ colorize (0.8.1)
11
+ diff-lcs (1.4.4)
12
+ docile (1.3.2)
13
+ fasterer (0.8.3)
14
+ colorize (~> 0.7)
15
+ ruby_parser (>= 3.14.1)
16
+ parallel (1.19.2)
17
+ parser (2.7.1.4)
18
+ ast (~> 2.4.1)
19
+ rainbow (3.0.0)
20
+ rake (12.3.3)
21
+ regexp_parser (1.7.1)
22
+ rexml (3.2.4)
23
+ rspec (3.9.0)
24
+ rspec-core (~> 3.9.0)
25
+ rspec-expectations (~> 3.9.0)
26
+ rspec-mocks (~> 3.9.0)
27
+ rspec-core (3.9.2)
28
+ rspec-support (~> 3.9.3)
29
+ rspec-expectations (3.9.2)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.9.0)
32
+ rspec-mocks (3.9.1)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.9.0)
35
+ rspec-support (3.9.3)
36
+ rubocop (0.88.0)
37
+ parallel (~> 1.10)
38
+ parser (>= 2.7.1.1)
39
+ rainbow (>= 2.2.2, < 4.0)
40
+ regexp_parser (>= 1.7)
41
+ rexml
42
+ rubocop-ast (>= 0.1.0, < 1.0)
43
+ ruby-progressbar (~> 1.7)
44
+ unicode-display_width (>= 1.4.0, < 2.0)
45
+ rubocop-ast (0.1.0)
46
+ parser (>= 2.7.0.1)
47
+ rubocop-rspec (1.42.0)
48
+ rubocop (>= 0.87.0)
49
+ ruby-progressbar (1.10.1)
50
+ ruby_parser (3.14.2)
51
+ sexp_processor (~> 4.9)
52
+ sexp_processor (4.15.0)
53
+ simplecov (0.18.5)
54
+ docile (~> 1.1)
55
+ simplecov-html (~> 0.11)
56
+ simplecov-html (0.12.2)
57
+ unicode-display_width (1.7.0)
58
+
59
+ PLATFORMS
60
+ ruby
61
+ x64-mingw32
62
+
63
+ DEPENDENCIES
64
+ codebreaker_kosinskiy!
65
+ fasterer
66
+ rake (~> 12.0)
67
+ rspec
68
+ rubocop
69
+ rubocop-rspec
70
+ simplecov
71
+
72
+ BUNDLED WITH
73
+ 2.1.4
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Kosinskiy Andrey
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.
@@ -0,0 +1,44 @@
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
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'codebreaker'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ 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 test` 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]/codebreaker. 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]/codebreaker/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 Codebreaker project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/codebreaker/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'codebreaker'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
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
@@ -0,0 +1,35 @@
1
+ require_relative 'lib/codebreaker/version'
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'codebreaker_kosinskiy'
5
+ spec.version = Codebreaker::VERSION
6
+ spec.authors = ['Kosinskiy Andrey']
7
+ spec.email = ['kosinskiy.andrey@ukr.net']
8
+
9
+ spec.summary = 'Super duper'
10
+ spec.description = 'it is my baby'
11
+ spec.homepage = 'https://github.com/AndreyKosinskiy/new-codebreaker/tree/master'
12
+ spec.license = 'MIT'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.3.0')
14
+
15
+ spec.metadata['allowed_push_host'] = 'https://rubygems.org'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/AndreyKosinskiy/new-codebreaker/tree/master'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/AndreyKosinskiy/new-codebreaker/tree/master'
20
+
21
+ # Specify which files should be added to the gem when it is released.
22
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
24
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ end
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+ spec.add_development_dependency 'fasterer'
30
+ spec.add_development_dependency 'rake', '~> 12.0'
31
+ spec.add_development_dependency 'rspec'
32
+ spec.add_development_dependency 'rubocop'
33
+ spec.add_development_dependency 'rubocop-rspec'
34
+ spec.add_development_dependency 'simplecov'
35
+ end
@@ -0,0 +1,9 @@
1
+ ---
2
+ - !ruby/object:Statistic::StatisticRow
3
+ rating: 1
4
+ player_name: Andrey
5
+ difficult_name: easy
6
+ init_attempts_count: 15
7
+ init_hints_count: 2
8
+ used_attempts_count: 0
9
+ used_hits_count: 0
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'codebreaker/version'
4
+ require_relative 'codebreaker/bootstrap'
5
+
6
+ module Codebreaker
7
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BeforeGame
4
+ class DifficultChooser
5
+ DIFFICULT_VARIANTS = [
6
+ { name: 'easy', attempts: 15, hints: 2 },
7
+ { name: 'medium', attempts: 10, hints: 1 },
8
+ { name: 'hell', attempts: 5, hints: 1 }
9
+ ].freeze
10
+
11
+ attr_accessor :name, :attempts_count, :hint
12
+
13
+ def initialize(difficult_variant:)
14
+ @name = difficult_variant[:name]
15
+ @attempts_count = difficult_variant[:attempts]
16
+ @hint = BeforeGame::Hint.new(hints_count: difficult_variant[:hints])
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module BeforeGame
4
+ class Hint
5
+ attr_accessor :hints_count, :hints_items
6
+
7
+ def initialize(hints_count:)
8
+ @hints_count = hints_count
9
+ end
10
+
11
+ def generate_hints(code)
12
+ @hints_items = code.sample(@hints_count)
13
+ end
14
+
15
+ def hint
16
+ return false if @hints_count.zero?
17
+
18
+ @hints_items.pop
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,12 @@
1
+ require_relative '../validation/registration'
2
+
3
+ module BeforeGame
4
+ class RegistrationPlayer
5
+ attr_reader :name
6
+
7
+ def initialize(name:)
8
+ Validation::Registration.validation(name: name)
9
+ @name = name
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,10 @@
1
+ require_relative 'validation/guess'
2
+ require_relative 'validation/registration'
3
+ require_relative 'before_game/difficult_chooser'
4
+ require_relative 'before_game/registration_player'
5
+ require_relative 'before_game/hint'
6
+ require_relative 'game/code_breaker'
7
+ require_relative 'game/code_maker'
8
+ require_relative 'statistic/statistic_row'
9
+ require_relative 'statistic/statistic_sheet'
10
+ require_relative 'yaml_saver'
@@ -0,0 +1,57 @@
1
+ require_relative '../validation/guess'
2
+ module Game
3
+ class CodeBreaker
4
+ include Validation
5
+ attr_accessor :current_stat
6
+
7
+ def initialize(player:, difficult:)
8
+ @current_stat = Statistic::StatisticRow.new(player: player, difficult_init: difficult)
9
+ @code = Game::CodeMaker.new.code
10
+ @hint = difficult.hint
11
+ @hint.generate_hints(@code)
12
+ end
13
+
14
+ def my_guess(input_value:)
15
+ Validation::Guess.validation(input_value: input_value)
16
+ input_value = input_value.split('').map(&:to_i)
17
+ @current_stat.used_attempts_count += 1 if can_use_attempts?
18
+ check_guess(input_value)
19
+ end
20
+
21
+ def player_win?(guess)
22
+ guess.count(true) == CodeMaker::CODE_DIGITS_COUNT
23
+ end
24
+
25
+ def each_element_as(arr, value)
26
+ return [] if arr.nil?
27
+
28
+ arr.map { |_element| value }
29
+ end
30
+
31
+ def check_guess(guess)
32
+ position_result = position_checker(guess)
33
+ include_result = digits_checker(guess, position_result)
34
+ each_element_as(position_result, true) + each_element_as(include_result, false)
35
+ end
36
+
37
+ def digits_checker(guess, uncheck_digits)
38
+ result = []
39
+ guess.map do |digit|
40
+ result.push(digit) if !uncheck_digits.include?(digit) && @code.include?(digit) && !result.include?(digit)
41
+ end
42
+ result.compact
43
+ end
44
+
45
+ def position_checker(guess)
46
+ @code.zip(guess).map { |code_digit, guess_digit| guess_digit if code_digit == guess_digit }.compact
47
+ end
48
+
49
+ def can_use_attempts?
50
+ @current_stat.init_attempts_count > @current_stat.used_attempts_count
51
+ end
52
+
53
+ def hint
54
+ @hint.hint
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,19 @@
1
+ module Game
2
+ class CodeMaker
3
+ CODE_DIGITS_COUNT = 4
4
+ CODE_VALUE_MIN = 1
5
+ CODE_VALUE_MAX = 6
6
+
7
+ attr_accessor :code
8
+
9
+ def initialize
10
+ @code = generate_code
11
+ end
12
+
13
+ private
14
+
15
+ def generate_code
16
+ Array.new(CODE_DIGITS_COUNT).map { (CODE_VALUE_MIN..CODE_VALUE_MAX).to_a.sample }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,17 @@
1
+ module Statistic
2
+ class StatisticRow
3
+ attr_accessor :player_name, :init_attempts_count, :init_hints_count,
4
+ :used_attempts_count, :used_hits_count, :difficult_name,
5
+ :rating
6
+
7
+ def initialize(player:, difficult_init:)
8
+ @rating = nil
9
+ @player_name = player.name
10
+ @difficult_name = difficult_init.name
11
+ @init_attempts_count = difficult_init.attempts_count
12
+ @init_hints_count = difficult_init.hint.hints_count
13
+ @used_attempts_count = 0
14
+ @used_hits_count = 0
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,27 @@
1
+ module Statistic
2
+ class StatisticSheet
3
+ attr_accessor :new_row
4
+
5
+ def initialize(storage:, row: nil)
6
+ @new_row = row
7
+ @rows = nil
8
+ @storage = storage
9
+ end
10
+
11
+ def store
12
+ @rows = Array(load)
13
+ if @rows.nil?
14
+ @rows = @new_row
15
+ else
16
+ @rows.append(@new_row)
17
+ @rows.sort_by! { |row| [row.init_attempts_count, row.used_attempts_count, row.used_hits_count] }
18
+ @rows.map.with_index { |row, rating| row.rating = rating + 1 }
19
+ end
20
+ @storage.store(@rows)
21
+ end
22
+
23
+ def load
24
+ @storage.load
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,17 @@
1
+ module Validation
2
+ class Guess
3
+ def self.validation(input_value:)
4
+ return if input_value.scan(/\D/).empty? && size_check(input_value) && number_in_range?(input_value)
5
+
6
+ raise ArgumentError, 'Guess - number, required, length - 4 digits, each digit is a number in the range 1-6'
7
+ end
8
+
9
+ def self.size_check(input_value)
10
+ input_value.size == Game::CodeMaker::CODE_DIGITS_COUNT
11
+ end
12
+
13
+ def self.number_in_range?(input_value, range = (Game::CodeMaker::CODE_VALUE_MIN..Game::CodeMaker::CODE_VALUE_MAX))
14
+ input_value.to_i.digits.all? { |digit| range.cover?(digit) }
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module Validation
2
+ class Registration
3
+ def self.validation(name:)
4
+ return if (name.is_a? String) && (3..20).cover?(name.size)
5
+
6
+ raise ArgumentError, 'Name - string, required, min length - 3 symbols, max length - 20'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Codebreaker
2
+ VERSION = '0.1.0'.freeze
3
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ # YamlSaver class for store/load entity
5
+ class YamlSaver
6
+ DEFAULT_YAML_FILE_NAME = 'data.yaml'
7
+
8
+ def initialize(file_name: DEFAULT_YAML_FILE_NAME, permitted_classes: [])
9
+ @file_name = file_name
10
+ @permitted_classes = permitted_classes
11
+
12
+ File.new(@file_name, File::CREAT) unless File.exist?(@file_name)
13
+ end
14
+
15
+ def store(entity = [])
16
+ File.open(@file_name, 'w') { |f| Psych.dump(entity, f) }
17
+ end
18
+
19
+ def load
20
+ options = { permitted_classes: @permitted_classes, aliases: true }
21
+ File.open(@file_name) { |file| Psych.safe_load(file, **options) }
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,161 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: codebreaker_kosinskiy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Kosinskiy Andrey
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2020-07-29 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'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '12.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '12.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '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'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '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: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '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'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: it is my baby
98
+ email:
99
+ - kosinskiy.andrey@ukr.net
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".circleci/config.yml"
105
+ - ".fasterer.yml"
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".rubocop.yml"
109
+ - ".ruby-version"
110
+ - ".travis.yml"
111
+ - CODE_OF_CONDUCT.md
112
+ - Gemfile
113
+ - Gemfile.lock
114
+ - LICENSE.txt
115
+ - README.md
116
+ - Rakefile
117
+ - bin/console
118
+ - bin/setup
119
+ - codebreaker.gemspec
120
+ - data.yaml
121
+ - lib/codebreaker.rb
122
+ - lib/codebreaker/before_game/difficult_chooser.rb
123
+ - lib/codebreaker/before_game/hint.rb
124
+ - lib/codebreaker/before_game/registration_player.rb
125
+ - lib/codebreaker/bootstrap.rb
126
+ - lib/codebreaker/game/code_breaker.rb
127
+ - lib/codebreaker/game/code_maker.rb
128
+ - lib/codebreaker/statistic/statistic_row.rb
129
+ - lib/codebreaker/statistic/statistic_sheet.rb
130
+ - lib/codebreaker/validation/guess.rb
131
+ - lib/codebreaker/validation/registration.rb
132
+ - lib/codebreaker/version.rb
133
+ - lib/codebreaker/yaml_saver.rb
134
+ homepage: https://github.com/AndreyKosinskiy/new-codebreaker/tree/master
135
+ licenses:
136
+ - MIT
137
+ metadata:
138
+ allowed_push_host: https://rubygems.org
139
+ homepage_uri: https://github.com/AndreyKosinskiy/new-codebreaker/tree/master
140
+ source_code_uri: https://github.com/AndreyKosinskiy/new-codebreaker/tree/master
141
+ changelog_uri: https://github.com/AndreyKosinskiy/new-codebreaker/tree/master
142
+ post_install_message:
143
+ rdoc_options: []
144
+ require_paths:
145
+ - lib
146
+ required_ruby_version: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - ">="
149
+ - !ruby/object:Gem::Version
150
+ version: 2.3.0
151
+ required_rubygems_version: !ruby/object:Gem::Requirement
152
+ requirements:
153
+ - - ">="
154
+ - !ruby/object:Gem::Version
155
+ version: '0'
156
+ requirements: []
157
+ rubygems_version: 3.1.2
158
+ signing_key:
159
+ specification_version: 4
160
+ summary: Super duper
161
+ test_files: []