code_brkr_game_training 0.7.2
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 +7 -0
- data/.circleci/config.yml +65 -0
- data/.fasterer.yml +22 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/.rubocop.yml +11 -0
- data/.travis.yml +6 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +74 -0
- data/README.md +4 -0
- data/Rakefile +8 -0
- data/bin/console +18 -0
- data/bin/setup +8 -0
- data/code_brkr_game_training.gemspec +37 -0
- data/lefthook.yml +9 -0
- data/lib/code_brkr_game_training.rb +8 -0
- data/lib/code_brkr_game_training/bootstrap/autoloader.rb +14 -0
- data/lib/code_brkr_game_training/data/.keep +0 -0
- data/lib/code_brkr_game_training/entities/code.rb +59 -0
- data/lib/code_brkr_game_training/entities/difficulty_controller.rb +64 -0
- data/lib/code_brkr_game_training/entities/game.rb +49 -0
- data/lib/code_brkr_game_training/entities/user.rb +25 -0
- data/lib/code_brkr_game_training/modules/file_operations.rb +24 -0
- data/lib/code_brkr_game_training/modules/statistics.rb +31 -0
- data/lib/code_brkr_game_training/modules/validator.rb +21 -0
- data/lib/code_brkr_game_training/version.rb +6 -0
- metadata +165 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b318c26b1c0fbbb3f410d204862100077cc1211f4a6fbd3f2c191e13e4418764
|
4
|
+
data.tar.gz: 882dab2737baf0cdcb0c8d182f09b8a6a59612ed7b1fc1208336265b6f1d3ef2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0b214b380fa55616ad912eb09f09c8cdb9c5796174af14dc17d837f78badf62720bb2b4e02bfb0455703be2f8e0f5f6f2795f186308036a1dc1073e4a5ed1eed
|
7
|
+
data.tar.gz: 5fa53619996367d8de6a0befbf8477421e86bfcaddf31119d156774580c78e8ad9aa02c44011ea30c1dfdc93803b88cd5ad6a03439184ac1f67429f6f53087f6
|
@@ -0,0 +1,65 @@
|
|
1
|
+
version: 2.1
|
2
|
+
|
3
|
+
executors:
|
4
|
+
default:
|
5
|
+
working_directory: ~/repo
|
6
|
+
description: Image for testing 3_1
|
7
|
+
docker:
|
8
|
+
- image: circleci/ruby:2.7.1
|
9
|
+
caches:
|
10
|
+
- &bundle_cache_full v1-repo-{{ checksum "Gemfile.lock" }}
|
11
|
+
- &bundle_cache v1-repo-
|
12
|
+
|
13
|
+
commands:
|
14
|
+
defaults:
|
15
|
+
steps:
|
16
|
+
- checkout
|
17
|
+
- restore_cache:
|
18
|
+
keys:
|
19
|
+
- *bundle_cache_full
|
20
|
+
- *bundle_cache
|
21
|
+
- run: bundle install --path vendor/bundle
|
22
|
+
- save_cache:
|
23
|
+
key: *bundle_cache_full
|
24
|
+
paths:
|
25
|
+
- vendor/bundle
|
26
|
+
run_linters:
|
27
|
+
description: command to start linters
|
28
|
+
steps:
|
29
|
+
- run:
|
30
|
+
name: rubocop
|
31
|
+
command: bundle exec rubocop
|
32
|
+
- run:
|
33
|
+
name: fasterer
|
34
|
+
command: bundle exec fasterer
|
35
|
+
run_specs:
|
36
|
+
steps:
|
37
|
+
- run:
|
38
|
+
name: run specs
|
39
|
+
command: |
|
40
|
+
mkdir /tmp/test-results
|
41
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
42
|
+
bundle exec rspec --format progress \
|
43
|
+
--out /tmp/test-results/rspec.xml \
|
44
|
+
$TEST_FILES
|
45
|
+
|
46
|
+
jobs:
|
47
|
+
lintering:
|
48
|
+
executor: default
|
49
|
+
steps:
|
50
|
+
- defaults
|
51
|
+
- run_linters
|
52
|
+
run_specs:
|
53
|
+
executor: default
|
54
|
+
steps:
|
55
|
+
- defaults
|
56
|
+
- run_specs
|
57
|
+
|
58
|
+
workflows:
|
59
|
+
version: 2
|
60
|
+
build:
|
61
|
+
jobs:
|
62
|
+
- lintering
|
63
|
+
- run_specs:
|
64
|
+
requires:
|
65
|
+
- lintering
|
data/.fasterer.yml
ADDED
@@ -0,0 +1,22 @@
|
|
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: true
|
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
|
+
|
21
|
+
exclude_paths:
|
22
|
+
- 'vendor/**/*.rb'
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
code_brkr_game_training (0.7.2)
|
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
|
+
lefthook (0.7.2)
|
17
|
+
parallel (1.19.2)
|
18
|
+
parser (2.7.1.4)
|
19
|
+
ast (~> 2.4.1)
|
20
|
+
rainbow (3.0.0)
|
21
|
+
rake (12.3.3)
|
22
|
+
regexp_parser (1.7.1)
|
23
|
+
rexml (3.2.4)
|
24
|
+
rspec (3.9.0)
|
25
|
+
rspec-core (~> 3.9.0)
|
26
|
+
rspec-expectations (~> 3.9.0)
|
27
|
+
rspec-mocks (~> 3.9.0)
|
28
|
+
rspec-core (3.9.2)
|
29
|
+
rspec-support (~> 3.9.3)
|
30
|
+
rspec-expectations (3.9.2)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.9.0)
|
33
|
+
rspec-mocks (3.9.1)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.9.0)
|
36
|
+
rspec-support (3.9.3)
|
37
|
+
rubocop (0.87.1)
|
38
|
+
parallel (~> 1.10)
|
39
|
+
parser (>= 2.7.1.1)
|
40
|
+
rainbow (>= 2.2.2, < 4.0)
|
41
|
+
regexp_parser (>= 1.7)
|
42
|
+
rexml
|
43
|
+
rubocop-ast (>= 0.1.0, < 1.0)
|
44
|
+
ruby-progressbar (~> 1.7)
|
45
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
46
|
+
rubocop-ast (0.1.0)
|
47
|
+
parser (>= 2.7.0.1)
|
48
|
+
rubocop-rspec (1.42.0)
|
49
|
+
rubocop (>= 0.87.0)
|
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
|
+
code_brkr_game_training!
|
65
|
+
fasterer (~> 0.8.3)
|
66
|
+
lefthook
|
67
|
+
rake (~> 12.0)
|
68
|
+
rspec (~> 3.0)
|
69
|
+
rubocop
|
70
|
+
rubocop-rspec
|
71
|
+
simplecov
|
72
|
+
|
73
|
+
BUNDLED WITH
|
74
|
+
2.1.4
|
data/README.md
ADDED
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
#!/usr/bin/env ruby
|
4
|
+
|
5
|
+
require 'bundler/setup'
|
6
|
+
require 'code_brkr_game_training'
|
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
|
+
|
16
|
+
|
17
|
+
require 'irb'
|
18
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative './lib/code_brkr_game_training/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'code_brkr_game_training'
|
7
|
+
spec.version = CodeBrkrGameTraining::VERSION
|
8
|
+
spec.authors = ['Pavel']
|
9
|
+
spec.email = ['pavlo.gord.developer@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'A gem created as an exercise in learning Ruby programming.'
|
12
|
+
spec.description = 'Do not use the code of this project for real tasks'
|
13
|
+
# spec.homepage = ""
|
14
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.7.1')
|
15
|
+
|
16
|
+
# spec.metadata["allowed_push_host"] = ""
|
17
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
# spec.metadata["source_code_uri"] = ""
|
19
|
+
# spec.metadata["changelog_uri"] = ""
|
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 = ""
|
27
|
+
# spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ['lib']
|
29
|
+
|
30
|
+
spec.add_development_dependency 'fasterer', '~> 0.8.3'
|
31
|
+
spec.add_development_dependency 'lefthook'
|
32
|
+
spec.add_development_dependency 'rake', '~> 12.0'
|
33
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
34
|
+
spec.add_development_dependency 'rubocop'
|
35
|
+
spec.add_development_dependency 'rubocop-rspec'
|
36
|
+
spec.add_development_dependency 'simplecov'
|
37
|
+
end
|
data/lefthook.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
require_relative '../version'
|
6
|
+
require_relative '../modules/file_operations'
|
7
|
+
|
8
|
+
require_relative '../modules/validator'
|
9
|
+
|
10
|
+
require_relative '../entities/user'
|
11
|
+
require_relative '../entities/difficulty_controller'
|
12
|
+
require_relative '../entities/code'
|
13
|
+
require_relative '../modules/statistics'
|
14
|
+
require_relative '../entities/game'
|
File without changes
|
@@ -0,0 +1,59 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Main Gem module
|
4
|
+
module CodeBrkrGameTraining
|
5
|
+
# Class class for storage and operations with secret code
|
6
|
+
class Code
|
7
|
+
include Validator
|
8
|
+
|
9
|
+
GAME_NUMBERS = { from: 1, to: 6, count: 4 }.freeze
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@secret_digit_arr = code_generator
|
13
|
+
end
|
14
|
+
|
15
|
+
def to_s
|
16
|
+
@secret_digit_arr.join
|
17
|
+
end
|
18
|
+
|
19
|
+
def code_check(user_digits_arr)
|
20
|
+
check_array_code_format(user_digits_arr)
|
21
|
+
alg_result = code_check_algorithm(@secret_digit_arr.clone, user_digits_arr)
|
22
|
+
result = {
|
23
|
+
in_position: GAME_NUMBERS[:count] - alg_result[:miss_indexes].length,
|
24
|
+
out_of_position: alg_result[:out_of_positions].length
|
25
|
+
}
|
26
|
+
result[:not_guessed] = GAME_NUMBERS[:count] - result[:in_position] - result[:out_of_position]
|
27
|
+
result
|
28
|
+
end
|
29
|
+
|
30
|
+
def random_secret_digit_according_indexes(exclude_indexes)
|
31
|
+
rand_index = @secret_digit_arr.each_index.reject { |index| exclude_indexes.include? index }.sample
|
32
|
+
{ index: rand_index, digit: @secret_digit_arr[rand_index] }
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def code_generator
|
38
|
+
Array.new(GAME_NUMBERS[:count]) { rand(GAME_NUMBERS[:from]..GAME_NUMBERS[:to]) }
|
39
|
+
end
|
40
|
+
|
41
|
+
def check_array_code_format(code_arr)
|
42
|
+
check_type(code_arr, Array)
|
43
|
+
raise GameError, 'incorrect_code_format' unless code_arr.size == GAME_NUMBERS[:count]
|
44
|
+
|
45
|
+
digits_range_arr = (GAME_NUMBERS[:from]..GAME_NUMBERS[:to]).to_a
|
46
|
+
code_arr.each { |digit| raise GameError, 'incorrect_code_format' unless digits_range_arr.member? digit }
|
47
|
+
end
|
48
|
+
|
49
|
+
def code_check_algorithm(system_arr, user_arr)
|
50
|
+
miss_indexes_arr = user_arr.each_index.reject { |user_index| user_arr[user_index] == system_arr[user_index] }
|
51
|
+
system_arr.select!.with_index { |_, sys_index| miss_indexes_arr.include? sys_index }
|
52
|
+
out_of_positions = miss_indexes_arr.collect do |miss_index|
|
53
|
+
found = system_arr.find_index { |sys_num| user_arr[miss_index] == sys_num }
|
54
|
+
found.nil? ? nil : system_arr.delete_at(found)
|
55
|
+
end
|
56
|
+
{ miss_indexes: miss_indexes_arr, out_of_positions: out_of_positions.compact }
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Main Gem module
|
4
|
+
module CodeBrkrGameTraining
|
5
|
+
# Class to control the difficulty of the game
|
6
|
+
class DifficultyController
|
7
|
+
include Validator
|
8
|
+
|
9
|
+
GAME_DIFFICULTIES = {
|
10
|
+
easy: { name: 'easy', attempts: 15, hints: 2 },
|
11
|
+
medium: { name: 'medium', attempts: 10, hints: 1 },
|
12
|
+
hell: { name: 'hell', attempts: 5, hints: 1 }
|
13
|
+
}.freeze
|
14
|
+
|
15
|
+
attr_reader :init_values, :actual_values
|
16
|
+
|
17
|
+
def self.difficulty_levels_order
|
18
|
+
GAME_DIFFICULTIES
|
19
|
+
.values
|
20
|
+
.sort_by { |difficulty| [difficulty[:attempts], difficulty[:hints]] }
|
21
|
+
.collect { |difficulty| difficulty[:name] }
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(dfclt_val)
|
25
|
+
@value_name = dfclt_val
|
26
|
+
validate
|
27
|
+
|
28
|
+
@init_values = GAME_DIFFICULTIES[dfclt_val.to_sym]
|
29
|
+
@actual_values = @init_values.clone
|
30
|
+
end
|
31
|
+
|
32
|
+
def guessing_attempts_available?
|
33
|
+
@actual_values[:attempts].positive?
|
34
|
+
end
|
35
|
+
|
36
|
+
def guessing_attempts_decrement!
|
37
|
+
guessing_attempts_decrement_permissible_check
|
38
|
+
@actual_values[:attempts] -= 1
|
39
|
+
end
|
40
|
+
|
41
|
+
def hints_available?
|
42
|
+
@actual_values[:hints].positive?
|
43
|
+
end
|
44
|
+
|
45
|
+
def hints_decrement!
|
46
|
+
hints_decrement_permissible_check
|
47
|
+
@actual_values[:hints] -= 1
|
48
|
+
end
|
49
|
+
|
50
|
+
private
|
51
|
+
|
52
|
+
def validate
|
53
|
+
check_contain_hash_key(@value_name, GAME_DIFFICULTIES)
|
54
|
+
end
|
55
|
+
|
56
|
+
def guessing_attempts_decrement_permissible_check
|
57
|
+
raise GameError, 'attempts_guessing_exhausted' unless guessing_attempts_available?
|
58
|
+
end
|
59
|
+
|
60
|
+
def hints_decrement_permissible_check
|
61
|
+
raise GameError, 'hints_exhausted' unless hints_available?
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Main Gem module
|
4
|
+
module CodeBrkrGameTraining
|
5
|
+
# Class for game
|
6
|
+
class Game
|
7
|
+
include Validator
|
8
|
+
extend Statistics
|
9
|
+
extend FileOperations
|
10
|
+
|
11
|
+
GameError = Class.new(StandardError)
|
12
|
+
|
13
|
+
attr_reader :user, :difficulty, :code
|
14
|
+
|
15
|
+
def initialize(user, difficulty)
|
16
|
+
@user = user
|
17
|
+
@difficulty = difficulty
|
18
|
+
validate
|
19
|
+
|
20
|
+
@code = Code.new
|
21
|
+
@hints_indexes = []
|
22
|
+
end
|
23
|
+
|
24
|
+
def code_guessing_attempt(digits_arr)
|
25
|
+
@difficulty.guessing_attempts_decrement!
|
26
|
+
result = @code.code_check(digits_arr)
|
27
|
+
if result[:in_position] == Code::GAME_NUMBERS[:count]
|
28
|
+
result = { win: true }
|
29
|
+
elsif !@difficulty.guessing_attempts_available?
|
30
|
+
result = { loss: true, сorrect_answer: @code.to_s }
|
31
|
+
end
|
32
|
+
result
|
33
|
+
end
|
34
|
+
|
35
|
+
def game_hint
|
36
|
+
@difficulty.hints_decrement!
|
37
|
+
hint = @code.random_secret_digit_according_indexes(@hints_indexes)
|
38
|
+
@hints_indexes << hint[:index]
|
39
|
+
hint[:digit]
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def validate
|
45
|
+
check_type(@user, User)
|
46
|
+
check_type(@difficulty, DifficultyController)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Main Gem module
|
4
|
+
module CodeBrkrGameTraining
|
5
|
+
# Class for game user
|
6
|
+
class User
|
7
|
+
include Validator
|
8
|
+
|
9
|
+
USERNAME_CONSTRAINTS = { min: 3, max: 20 }.freeze
|
10
|
+
|
11
|
+
attr_reader :name
|
12
|
+
|
13
|
+
def initialize(name)
|
14
|
+
@name = name
|
15
|
+
validate
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def validate
|
21
|
+
check_type(@name, String)
|
22
|
+
check_length(@name, USERNAME_CONSTRAINTS)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Main Gem module
|
4
|
+
module CodeBrkrGameTraining
|
5
|
+
# Module for file operations
|
6
|
+
module FileOperations
|
7
|
+
def save_to_file(data, path)
|
8
|
+
yml = YAML.dump(data)
|
9
|
+
File.open(path, 'a') { |yml_file| yml_file.write(yml) }
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_from_file(path)
|
13
|
+
begin
|
14
|
+
yml_data = File.open(path, &:read)
|
15
|
+
rescue Errno::ENOENT
|
16
|
+
yml_data = ''
|
17
|
+
end
|
18
|
+
|
19
|
+
YAML.load_stream(
|
20
|
+
yml_data
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Main Gem module
|
4
|
+
module CodeBrkrGameTraining
|
5
|
+
# Module for game stats
|
6
|
+
module Statistics
|
7
|
+
STATISTICS_FILE_PATH = File.dirname(File.expand_path(__FILE__)) + '/../data/game_stats.yml'
|
8
|
+
|
9
|
+
def save_game_results!(user, difficulty)
|
10
|
+
difficulty_init = difficulty.init_values
|
11
|
+
difficulty_actual = difficulty.actual_values
|
12
|
+
game_session = {
|
13
|
+
name: user.name, difficulty: difficulty_init[:name],
|
14
|
+
attempts_total: difficulty_init[:attempts], hints_total: difficulty_init[:hints]
|
15
|
+
}
|
16
|
+
game_session[:attempts_used] = game_session[:attempts_total] - difficulty_actual[:attempts]
|
17
|
+
game_session[:hints_used] = game_session[:hints_total] - difficulty_actual[:hints]
|
18
|
+
save_to_file(game_session, STATISTICS_FILE_PATH)
|
19
|
+
end
|
20
|
+
|
21
|
+
def full_statistics
|
22
|
+
games_array = load_from_file(STATISTICS_FILE_PATH)
|
23
|
+
return games_array if games_array.empty?
|
24
|
+
|
25
|
+
difficulty_order = DifficultyController.difficulty_levels_order
|
26
|
+
games_array.sort_by do |game|
|
27
|
+
[difficulty_order.index(game[:difficulty]), game[:attempts_used], game[:hints_used]]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Main Gem module
|
4
|
+
module CodeBrkrGameTraining
|
5
|
+
# Data validation module
|
6
|
+
module Validator
|
7
|
+
DataValidError = Class.new(StandardError)
|
8
|
+
|
9
|
+
def check_type(data, check_type)
|
10
|
+
raise DataValidError, 'unexpected_type' unless data.instance_of? check_type
|
11
|
+
end
|
12
|
+
|
13
|
+
def check_length(data, check)
|
14
|
+
raise DataValidError, 'unexpected_length' unless (check[:min]..check[:max]).cover? data.length
|
15
|
+
end
|
16
|
+
|
17
|
+
def check_contain_hash_key(val, hash)
|
18
|
+
raise DataValidError, 'hash_key_not_found' unless hash.key? val.to_sym
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: code_brkr_game_training
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.7.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Pavel
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-07-25 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: lefthook
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '12.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '12.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop
|
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: rubocop-rspec
|
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
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
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
|
+
description: Do not use the code of this project for real tasks
|
112
|
+
email:
|
113
|
+
- pavlo.gord.developer@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".circleci/config.yml"
|
119
|
+
- ".fasterer.yml"
|
120
|
+
- ".gitignore"
|
121
|
+
- ".rspec"
|
122
|
+
- ".rubocop.yml"
|
123
|
+
- ".travis.yml"
|
124
|
+
- Gemfile
|
125
|
+
- Gemfile.lock
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- code_brkr_game_training.gemspec
|
131
|
+
- lefthook.yml
|
132
|
+
- lib/code_brkr_game_training.rb
|
133
|
+
- lib/code_brkr_game_training/bootstrap/autoloader.rb
|
134
|
+
- lib/code_brkr_game_training/data/.keep
|
135
|
+
- lib/code_brkr_game_training/entities/code.rb
|
136
|
+
- lib/code_brkr_game_training/entities/difficulty_controller.rb
|
137
|
+
- lib/code_brkr_game_training/entities/game.rb
|
138
|
+
- lib/code_brkr_game_training/entities/user.rb
|
139
|
+
- lib/code_brkr_game_training/modules/file_operations.rb
|
140
|
+
- lib/code_brkr_game_training/modules/statistics.rb
|
141
|
+
- lib/code_brkr_game_training/modules/validator.rb
|
142
|
+
- lib/code_brkr_game_training/version.rb
|
143
|
+
homepage:
|
144
|
+
licenses: []
|
145
|
+
metadata: {}
|
146
|
+
post_install_message:
|
147
|
+
rdoc_options: []
|
148
|
+
require_paths:
|
149
|
+
- lib
|
150
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
151
|
+
requirements:
|
152
|
+
- - ">="
|
153
|
+
- !ruby/object:Gem::Version
|
154
|
+
version: 2.7.1
|
155
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
requirements: []
|
161
|
+
rubygems_version: 3.1.2
|
162
|
+
signing_key:
|
163
|
+
specification_version: 4
|
164
|
+
summary: A gem created as an exercise in learning Ruby programming.
|
165
|
+
test_files: []
|