codebreaker_ruban 0.1.0
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 +46 -0
- data/.fasterer.yml +19 -0
- data/.gitignore +2 -0
- data/.rspec +1 -0
- data/.rspec_status +89 -0
- data/.rubocop.yml +14 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +7 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +82 -0
- data/LICENSE.txt +21 -0
- data/README.md +43 -0
- data/Rakefile +6 -0
- data/autoload.rb +13 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/codebreake_ruban.gemspec +44 -0
- data/index.rb +5 -0
- data/lib/app/config/config_i18n.rb +3 -0
- data/lib/app/config/locales/en.yml +40 -0
- data/lib/app/entities/console.rb +145 -0
- data/lib/app/entities/game.rb +104 -0
- data/lib/app/entities/message.rb +91 -0
- data/lib/app/entities/statistic.rb +25 -0
- data/lib/app/entities/storage.rb +22 -0
- data/lib/app/entities/user.rb +20 -0
- data/lib/app/module/validation.rb +17 -0
- data/lib/app/store/.keep +0 -0
- data/lib/codebreaker_ruban.rb +4 -0
- data/lib/codebreaker_ruban/version.rb +3 -0
- metadata +203 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4655f1b71e3557b3451a1beddb81be90eb5c76ebc93f612a76d92621bc4de67d
|
4
|
+
data.tar.gz: 6f87815ad7c6cca1b33c3b9a303da5729e083c8cb9b68b779649e84ab29d3c19
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a76354c5d6fb694cf368f66f279565807078f6c5cb9d58c547c9d085b13de3683b5dc484a49ebeadba81029bbaaf5f7ab939f6bf743f3cb4d29ea06349e68ae
|
7
|
+
data.tar.gz: bb88e054c6830db20345eb2808a925c195f1166295952962c71224cf8c2cf308da2d72daa4f4777c9501e20285021ead93ed324a1d474699c32b1b34bdb17dc1
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
2
|
+
#
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
+
#
|
5
|
+
version: 2
|
6
|
+
jobs:
|
7
|
+
build:
|
8
|
+
docker:
|
9
|
+
# specify the version you desire here
|
10
|
+
- image: circleci/ruby:2.5.1-node-browsers
|
11
|
+
|
12
|
+
working_directory: ~/repo
|
13
|
+
|
14
|
+
steps:
|
15
|
+
- checkout
|
16
|
+
|
17
|
+
- restore_cache:
|
18
|
+
keys:
|
19
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
20
|
+
# fallback to using the latest cache if no exact match is found
|
21
|
+
- v1-dependencies-
|
22
|
+
|
23
|
+
- run:
|
24
|
+
name: install dependencies
|
25
|
+
command: |
|
26
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
27
|
+
- save_cache:
|
28
|
+
paths:
|
29
|
+
- ./vendor/bundle
|
30
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
31
|
+
|
32
|
+
- run:
|
33
|
+
name: run tests
|
34
|
+
command: |
|
35
|
+
mkdir /tmp/test-results
|
36
|
+
TEST_FILES="$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)"
|
37
|
+
|
38
|
+
bundle exec rspec --format progress \
|
39
|
+
--out /tmp/test-results/rspec.xml \
|
40
|
+
--format progress \
|
41
|
+
$TEST_FILES
|
42
|
+
- store_test_results:
|
43
|
+
path: /tmp/test-results
|
44
|
+
- store_artifacts:
|
45
|
+
path: /tmp/test-results
|
46
|
+
destination: test-results
|
data/.fasterer.yml
ADDED
@@ -0,0 +1,19 @@
|
|
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
|
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--require spec_helper
|
data/.rspec_status
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
example_id | status | run_time |
|
2
|
+
------------------------------------- | ------ | --------------- |
|
3
|
+
./spec/codebreaker_ruban_spec.rb[1:1] | passed | 0.0004 seconds |
|
4
|
+
./spec/console_spec.rb[1:1:1] | passed | 0.00032 seconds |
|
5
|
+
./spec/console_spec.rb[1:2:1] | passed | 0.00006 seconds |
|
6
|
+
./spec/console_spec.rb[1:2:2] | passed | 0.00005 seconds |
|
7
|
+
./spec/console_spec.rb[1:2:3] | passed | 0.00004 seconds |
|
8
|
+
./spec/console_spec.rb[1:2:4] | passed | 0.00004 seconds |
|
9
|
+
./spec/console_spec.rb[1:2:5] | passed | 0.00005 seconds |
|
10
|
+
./spec/console_spec.rb[1:2:6] | passed | 0.00004 seconds |
|
11
|
+
./spec/console_spec.rb[1:2:7] | passed | 0.00004 seconds |
|
12
|
+
./spec/console_spec.rb[1:3:1] | passed | 0.0103 seconds |
|
13
|
+
./spec/console_spec.rb[1:3:2] | passed | 0.00071 seconds |
|
14
|
+
./spec/console_spec.rb[1:3:3] | passed | 0.00055 seconds |
|
15
|
+
./spec/console_spec.rb[1:3:4] | passed | 0.00064 seconds |
|
16
|
+
./spec/console_spec.rb[1:3:5] | passed | 0.00064 seconds |
|
17
|
+
./spec/console_spec.rb[1:4:1:1] | passed | 0.00075 seconds |
|
18
|
+
./spec/console_spec.rb[1:4:2:1] | passed | 0.00071 seconds |
|
19
|
+
./spec/console_spec.rb[1:5:1] | passed | 0.00049 seconds |
|
20
|
+
./spec/console_spec.rb[1:5:2] | passed | 0.00054 seconds |
|
21
|
+
./spec/console_spec.rb[1:6:1] | passed | 0.00047 seconds |
|
22
|
+
./spec/console_spec.rb[1:6:2] | passed | 0.00053 seconds |
|
23
|
+
./spec/console_spec.rb[1:6:3] | passed | 0.00055 seconds |
|
24
|
+
./spec/console_spec.rb[1:6:4] | passed | 0.00053 seconds |
|
25
|
+
./spec/console_spec.rb[1:6:5] | passed | 0.00055 seconds |
|
26
|
+
./spec/console_spec.rb[1:6:6] | passed | 0.0006 seconds |
|
27
|
+
./spec/console_spec.rb[1:7:1] | passed | 0.0006 seconds |
|
28
|
+
./spec/console_spec.rb[1:7:2] | passed | 0.00063 seconds |
|
29
|
+
./spec/console_spec.rb[1:7:3] | passed | 0.00056 seconds |
|
30
|
+
./spec/console_spec.rb[1:8:1] | passed | 0.00064 seconds |
|
31
|
+
./spec/console_spec.rb[1:9:1] | passed | 0.00099 seconds |
|
32
|
+
./spec/console_spec.rb[1:9:2] | passed | 0.00189 seconds |
|
33
|
+
./spec/console_spec.rb[1:10:1] | passed | 0.00098 seconds |
|
34
|
+
./spec/console_spec.rb[1:10:2] | passed | 0.00137 seconds |
|
35
|
+
./spec/console_spec.rb[1:10:3] | passed | 0.0011 seconds |
|
36
|
+
./spec/console_spec.rb[1:11:1] | passed | 0.00056 seconds |
|
37
|
+
./spec/console_spec.rb[1:11:2] | passed | 0.00056 seconds |
|
38
|
+
./spec/game_spec.rb[1:1:1] | passed | 0.00016 seconds |
|
39
|
+
./spec/game_spec.rb[1:1:2] | passed | 0.00008 seconds |
|
40
|
+
./spec/game_spec.rb[1:1:3] | passed | 0.00007 seconds |
|
41
|
+
./spec/game_spec.rb[1:1:4] | passed | 0.00008 seconds |
|
42
|
+
./spec/game_spec.rb[1:2:1] | passed | 0.00023 seconds |
|
43
|
+
./spec/game_spec.rb[1:2:2] | passed | 0.00018 seconds |
|
44
|
+
./spec/game_spec.rb[1:3:1:1] | passed | 0.00009 seconds |
|
45
|
+
./spec/game_spec.rb[1:3:1:2] | passed | 0.00008 seconds |
|
46
|
+
./spec/game_spec.rb[1:4:1] | passed | 0.00006 seconds |
|
47
|
+
./spec/game_spec.rb[1:5:1] | passed | 0.00007 seconds |
|
48
|
+
./spec/game_spec.rb[1:5:2] | passed | 0.00006 seconds |
|
49
|
+
./spec/game_spec.rb[1:5:3] | passed | 0.00006 seconds |
|
50
|
+
./spec/game_spec.rb[1:5:4] | passed | 0.00006 seconds |
|
51
|
+
./spec/game_spec.rb[1:5:5] | passed | 0.00006 seconds |
|
52
|
+
./spec/game_spec.rb[1:5:6] | passed | 0.00006 seconds |
|
53
|
+
./spec/game_spec.rb[1:5:7] | passed | 0.00008 seconds |
|
54
|
+
./spec/game_spec.rb[1:5:8] | passed | 0.00006 seconds |
|
55
|
+
./spec/game_spec.rb[1:5:9] | passed | 0.00007 seconds |
|
56
|
+
./spec/game_spec.rb[1:5:10] | passed | 0.00006 seconds |
|
57
|
+
./spec/game_spec.rb[1:5:11] | passed | 0.00006 seconds |
|
58
|
+
./spec/game_spec.rb[1:5:12] | passed | 0.00006 seconds |
|
59
|
+
./spec/game_spec.rb[1:5:13] | passed | 0.00008 seconds |
|
60
|
+
./spec/game_spec.rb[1:5:14] | passed | 0.00006 seconds |
|
61
|
+
./spec/game_spec.rb[1:5:15] | passed | 0.00006 seconds |
|
62
|
+
./spec/message_spec.rb[1:1] | passed | 0.00106 seconds |
|
63
|
+
./spec/message_spec.rb[1:2] | passed | 0.00013 seconds |
|
64
|
+
./spec/message_spec.rb[1:3] | passed | 0.00009 seconds |
|
65
|
+
./spec/message_spec.rb[1:4] | passed | 0.0001 seconds |
|
66
|
+
./spec/message_spec.rb[1:5] | passed | 0.0001 seconds |
|
67
|
+
./spec/message_spec.rb[1:6] | passed | 0.00011 seconds |
|
68
|
+
./spec/message_spec.rb[1:7] | passed | 0.0001 seconds |
|
69
|
+
./spec/message_spec.rb[1:8] | passed | 0.00008 seconds |
|
70
|
+
./spec/message_spec.rb[1:9] | passed | 0.00009 seconds |
|
71
|
+
./spec/message_spec.rb[1:10] | passed | 0.00008 seconds |
|
72
|
+
./spec/message_spec.rb[1:11] | passed | 0.00008 seconds |
|
73
|
+
./spec/message_spec.rb[1:12] | passed | 0.00008 seconds |
|
74
|
+
./spec/message_spec.rb[1:13] | passed | 0.0001 seconds |
|
75
|
+
./spec/message_spec.rb[1:14] | passed | 0.00008 seconds |
|
76
|
+
./spec/message_spec.rb[1:15] | passed | 0.00007 seconds |
|
77
|
+
./spec/message_spec.rb[1:16] | passed | 0.00008 seconds |
|
78
|
+
./spec/message_spec.rb[1:17] | passed | 0.00007 seconds |
|
79
|
+
./spec/message_spec.rb[1:18] | passed | 0.00008 seconds |
|
80
|
+
./spec/message_spec.rb[1:19] | passed | 0.00007 seconds |
|
81
|
+
./spec/statistic_spec.rb[1:1:1] | passed | 0.00027 seconds |
|
82
|
+
./spec/statistic_spec.rb[1:1:2] | passed | 0.00021 seconds |
|
83
|
+
./spec/storage_spec.rb[1:1:1] | passed | 0.0009 seconds |
|
84
|
+
./spec/storage_spec.rb[1:2:1] | passed | 0.00075 seconds |
|
85
|
+
./spec/storage_spec.rb[1:2:2:1] | passed | 0.00012 seconds |
|
86
|
+
./spec/user_spec.rb[1:1:1] | passed | 0.0001 seconds |
|
87
|
+
./spec/user_spec.rb[1:2:1] | passed | 0.00006 seconds |
|
88
|
+
./spec/user_spec.rb[1:3:1] | passed | 0.00023 seconds |
|
89
|
+
./spec/user_spec.rb[1:3:2] | passed | 0.00017 seconds |
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
Style/Encoding:
|
3
|
+
Enabled: false
|
4
|
+
Metrics/LineLength:
|
5
|
+
Max: 120
|
6
|
+
Metrics/ClassLength:
|
7
|
+
Max: 125
|
8
|
+
Metrics/MethodLength:
|
9
|
+
Max: 11
|
10
|
+
Metrics/BlockLength:
|
11
|
+
ExcludedMethods: ['describe']
|
12
|
+
Max: 30
|
13
|
+
Documentation:
|
14
|
+
Enabled: false
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Codebreaker
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-2.5.1
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -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 moaner48@gmail.com. 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 [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
codebreaker_ruban (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.0)
|
10
|
+
coderay (1.1.2)
|
11
|
+
colorize (0.8.1)
|
12
|
+
concurrent-ruby (1.1.4)
|
13
|
+
diff-lcs (1.3)
|
14
|
+
docile (1.3.1)
|
15
|
+
fasterer (0.4.1)
|
16
|
+
colorize (~> 0.7)
|
17
|
+
ruby_parser (~> 3.11.0)
|
18
|
+
i18n (1.4.0)
|
19
|
+
concurrent-ruby (~> 1.0)
|
20
|
+
jaro_winkler (1.5.1)
|
21
|
+
json (2.1.0)
|
22
|
+
method_source (0.9.2)
|
23
|
+
parallel (1.12.1)
|
24
|
+
parser (2.5.3.0)
|
25
|
+
ast (~> 2.4.0)
|
26
|
+
powerpack (0.1.2)
|
27
|
+
pry (0.12.2)
|
28
|
+
coderay (~> 1.1.0)
|
29
|
+
method_source (~> 0.9.0)
|
30
|
+
rainbow (3.0.0)
|
31
|
+
rake (10.5.0)
|
32
|
+
rspec (3.8.0)
|
33
|
+
rspec-core (~> 3.8.0)
|
34
|
+
rspec-expectations (~> 3.8.0)
|
35
|
+
rspec-mocks (~> 3.8.0)
|
36
|
+
rspec-core (3.8.0)
|
37
|
+
rspec-support (~> 3.8.0)
|
38
|
+
rspec-expectations (3.8.2)
|
39
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
40
|
+
rspec-support (~> 3.8.0)
|
41
|
+
rspec-mocks (3.8.0)
|
42
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
43
|
+
rspec-support (~> 3.8.0)
|
44
|
+
rspec-support (3.8.0)
|
45
|
+
rubocop (0.60.0)
|
46
|
+
jaro_winkler (~> 1.5.1)
|
47
|
+
parallel (~> 1.10)
|
48
|
+
parser (>= 2.5, != 2.5.1.1)
|
49
|
+
powerpack (~> 0.1)
|
50
|
+
rainbow (>= 2.2.2, < 4.0)
|
51
|
+
ruby-progressbar (~> 1.7)
|
52
|
+
unicode-display_width (~> 1.4.0)
|
53
|
+
rubocop-rspec (1.30.1)
|
54
|
+
rubocop (>= 0.60.0)
|
55
|
+
ruby-progressbar (1.10.0)
|
56
|
+
ruby_parser (3.11.0)
|
57
|
+
sexp_processor (~> 4.9)
|
58
|
+
sexp_processor (4.11.0)
|
59
|
+
simplecov (0.16.1)
|
60
|
+
docile (~> 1.1)
|
61
|
+
json (>= 1.8, < 3)
|
62
|
+
simplecov-html (~> 0.10.0)
|
63
|
+
simplecov-html (0.10.2)
|
64
|
+
unicode-display_width (1.4.0)
|
65
|
+
|
66
|
+
PLATFORMS
|
67
|
+
ruby
|
68
|
+
|
69
|
+
DEPENDENCIES
|
70
|
+
bundler (~> 1.17)
|
71
|
+
codebreaker_ruban!
|
72
|
+
fasterer
|
73
|
+
i18n
|
74
|
+
pry
|
75
|
+
rake (~> 10.0)
|
76
|
+
rspec (~> 3.0)
|
77
|
+
rubocop
|
78
|
+
rubocop-rspec
|
79
|
+
simplecov
|
80
|
+
|
81
|
+
BUNDLED WITH
|
82
|
+
1.17.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2019 IRuban
|
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,43 @@
|
|
1
|
+
# CodebreakerRuban
|
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_ruban`. 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_ruban'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install codebreaker_ruban
|
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]/codebreaker_ruban. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
|
41
|
+
## Code of Conduct
|
42
|
+
|
43
|
+
Everyone interacting in the CodebreakerRuban project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/codebreaker_ruban/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/autoload.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'yaml'
|
4
|
+
require 'i18n'
|
5
|
+
require 'pry'
|
6
|
+
require_relative 'lib/app/module/validation.rb'
|
7
|
+
require_relative 'lib/app/entities/statistic.rb'
|
8
|
+
require_relative 'lib/app/entities/storage.rb'
|
9
|
+
require_relative 'lib/app/entities/user.rb'
|
10
|
+
require_relative 'lib/app/entities/game.rb'
|
11
|
+
require_relative 'lib/app/entities/message.rb'
|
12
|
+
require_relative 'lib/app/entities/console.rb'
|
13
|
+
require_relative 'lib/app/config/config_i18n.rb'
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "codebreaker_ruban"
|
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__)
|
data/bin/setup
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("lib", __dir__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "codebreaker_ruban/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "codebreaker_ruban"
|
8
|
+
spec.version = CodebreakerRuban::VERSION
|
9
|
+
spec.authors = ["IRuban"]
|
10
|
+
spec.email = ["moaner48@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = 'CodebreakerRuban'
|
13
|
+
spec.description = 'Game'
|
14
|
+
spec.homepage = 'https://github.com/IRuban/codebreaker_ruban'
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
18
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata["allowed_push_host"] = 'https://rubygems.org'
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against " \
|
23
|
+
"public gem pushes."
|
24
|
+
end
|
25
|
+
|
26
|
+
# Specify which files should be added to the gem when it is released.
|
27
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
28
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
29
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
|
+
end
|
31
|
+
spec.bindir = "exe"
|
32
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
33
|
+
spec.require_paths = ["lib"]
|
34
|
+
|
35
|
+
spec.add_development_dependency "bundler", "~> 1.17"
|
36
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
37
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
38
|
+
spec.add_development_dependency "i18n"
|
39
|
+
spec.add_development_dependency "fasterer"
|
40
|
+
spec.add_development_dependency "pry"
|
41
|
+
spec.add_development_dependency "rubocop"
|
42
|
+
spec.add_development_dependency "rubocop-rspec"
|
43
|
+
spec.add_development_dependency "simplecov"
|
44
|
+
end
|
data/index.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
en:
|
2
|
+
greeting: 'welcome'
|
3
|
+
choice_option: "Enter %{start}, %{rules}, %{stats} or %{exit}"
|
4
|
+
rules: "Game Rules\n
|
5
|
+
Codebreaker is a logic game in which a code-breaker tries to break a secret code created by a code-maker. The codemaker, which will be played by the application we’re going to write, creates a secret code of four numbers between 1 and 6.\n
|
6
|
+
The codebreaker gets some number of chances to break the code (depends on chosen difficulty). In each turn, the codebreaker makes a guess of 4 numbers. The codemaker then marks the guess with up to 4 signs - + or - or empty spaces.\n
|
7
|
+
A + indicates an exact match - one of the numbers in the guess is the same as one of the numbers in the secret code and in the same position. For example\n
|
8
|
+
Secret number - 1234\n
|
9
|
+
Input number - 6264\n
|
10
|
+
Number of pluses - 2 (second and fourth position)\n
|
11
|
+
A - indicates a number match - one of the numbers in the guess is the same as one of the numbers in the secret code but in a different position. For example\n
|
12
|
+
Secret number - 1234\n
|
13
|
+
Input number - 6462\n
|
14
|
+
Number of minuses - 2 (second and fourth position)\n
|
15
|
+
An empty space indicates that there is not a current digit in a secret number.\n
|
16
|
+
If codebreaker inputs the exact number as a secret number - codebreaker wins the game. If all attempts are spent - codebreaker loses.\n
|
17
|
+
Codebreaker also has some number of hints(depends on chosen difficulty). If a user takes a hint - he receives back a separate digit of the secret code.\n"
|
18
|
+
wrong_command: 'You have passed unexpected command. Please choose one from listed commands'
|
19
|
+
enter_name: 'Enter your name '
|
20
|
+
choice_difficulty: "Choice difficulty %{easy} %{medium} %{hell}"
|
21
|
+
enter_code: 'Enter your code'
|
22
|
+
goodbye: 'Goodbye'
|
23
|
+
ended_attempts: 'Ended attempts'
|
24
|
+
save: 'Are you want save?'
|
25
|
+
restart: 'Are you want restart?'
|
26
|
+
statistic_empty: 'Statistic is empty'
|
27
|
+
result_save: 'Your result saved'
|
28
|
+
win: 'You win'
|
29
|
+
lose: 'You lose'
|
30
|
+
show_stats: "name: %{name}\n
|
31
|
+
difficulty: %{difficulty}\n
|
32
|
+
attempts_used: %{attempts_used}\n
|
33
|
+
attempts_total: %{attempts_total}\n
|
34
|
+
hints_total: %{hints_total}\n
|
35
|
+
hints_used: %{hints_used}\n"
|
36
|
+
show_secret_code: 'Secret code - %{secret_code} '
|
37
|
+
errors:
|
38
|
+
error_name_size: 'Name must be %{min} - %{max}'
|
39
|
+
error_difficulty: 'Not found difficulty'
|
40
|
+
error_guess_code: 'Error enter code'
|
@@ -0,0 +1,145 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CodebreakerRuban
|
4
|
+
class Console
|
5
|
+
attr_accessor :state, :game, :user, :difficulty
|
6
|
+
|
7
|
+
OPTION = {
|
8
|
+
rules: 'rules',
|
9
|
+
start: 'start',
|
10
|
+
stats: 'stats',
|
11
|
+
exit: 'exit'
|
12
|
+
}.freeze
|
13
|
+
HINT = 'hint'
|
14
|
+
WIN = '++++'
|
15
|
+
YES = %w[yes y].freeze
|
16
|
+
EASY_STRING = 'easy'
|
17
|
+
MEDIUM_STRING = 'medium'
|
18
|
+
HELL_STRING = 'hell'
|
19
|
+
|
20
|
+
def initialize
|
21
|
+
set_state(:choice_option)
|
22
|
+
end
|
23
|
+
|
24
|
+
def run
|
25
|
+
Message.greeting
|
26
|
+
loop do
|
27
|
+
send(state)
|
28
|
+
break if state == :game_over
|
29
|
+
end
|
30
|
+
Message.goodbye
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def choice_option
|
36
|
+
Message.choice_option(*OPTION.values)
|
37
|
+
process_user_input do |input|
|
38
|
+
case input
|
39
|
+
when OPTION[:start] then set_state(:choice_name)
|
40
|
+
when OPTION[:rules] then Message.rules
|
41
|
+
when OPTION[:stats] then Statistic.show_stats
|
42
|
+
else
|
43
|
+
Message.wrong_command
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def choice_name
|
49
|
+
Message.enter_name
|
50
|
+
process_user_input do |input|
|
51
|
+
@user = User.new(input)
|
52
|
+
@user.validate(input)
|
53
|
+
@user.errors.empty? ? set_state(:choice_difficulty) : Message.display(@user.errors)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def choice_difficulty
|
58
|
+
Message.choice_difficulty(EASY_STRING, MEDIUM_STRING, HELL_STRING)
|
59
|
+
process_user_input do |input|
|
60
|
+
@difficulty = case input
|
61
|
+
when EASY_STRING then Game::EASY
|
62
|
+
when MEDIUM_STRING then Game::MEDIUM
|
63
|
+
when HELL_STRING then Game::HELL
|
64
|
+
end
|
65
|
+
return Message.error_difficulty unless @difficulty
|
66
|
+
|
67
|
+
set_state(:start_game)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def start_game
|
72
|
+
@game = Game.new(@difficulty, @user)
|
73
|
+
set_state(:check_guess)
|
74
|
+
end
|
75
|
+
|
76
|
+
def check_guess
|
77
|
+
Message.enter_code
|
78
|
+
process_user_input do |input|
|
79
|
+
if input == HINT
|
80
|
+
Message.display(@game.hint_use)
|
81
|
+
else
|
82
|
+
@game.validate_guess_input(input)
|
83
|
+
@game.errors.empty? ? check_win(input) : Message.display(@game.errors)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def check_win(input)
|
89
|
+
if @game.check_attemps
|
90
|
+
check_secret_and_guess = @game.check_user_input(input)
|
91
|
+
Message.display(check_secret_and_guess)
|
92
|
+
Message.win if game_result(check_secret_and_guess)
|
93
|
+
else
|
94
|
+
Message.lose
|
95
|
+
Message.show_secret_code(@game.secret_code)
|
96
|
+
set_state(:restart_game)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def game_result(check_secret_and_guess)
|
101
|
+
return unless check_secret_and_guess == WIN
|
102
|
+
|
103
|
+
set_state(:save_result)
|
104
|
+
end
|
105
|
+
|
106
|
+
def save_result
|
107
|
+
Message.save
|
108
|
+
if YES.include? user_input
|
109
|
+
Storage.save_in_store(@game.to_h)
|
110
|
+
Message.result_save
|
111
|
+
end
|
112
|
+
set_state(:restart_game)
|
113
|
+
end
|
114
|
+
|
115
|
+
def restart_game
|
116
|
+
Message.restart
|
117
|
+
if YES.include? user_input
|
118
|
+
set_state(:choice_option)
|
119
|
+
else
|
120
|
+
set_state(:game_over)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def user_input
|
125
|
+
gets.chomp.downcase
|
126
|
+
end
|
127
|
+
|
128
|
+
def game_over
|
129
|
+
set_state(:game_over)
|
130
|
+
end
|
131
|
+
|
132
|
+
def process_user_input
|
133
|
+
input = gets.chomp.downcase
|
134
|
+
if input == OPTION[:exit]
|
135
|
+
set_state(:game_over)
|
136
|
+
else
|
137
|
+
yield(input)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def set_state(console_state)
|
142
|
+
@state = console_state
|
143
|
+
end
|
144
|
+
end
|
145
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CodebreakerRuban
|
4
|
+
class Game
|
5
|
+
include Validation
|
6
|
+
attr_reader :difficulty, :attempts_total, :hints_total, :user, :secret_code
|
7
|
+
attr_accessor :attempts_used, :hints_used, :errors
|
8
|
+
|
9
|
+
LENGTH_GUESS = 4
|
10
|
+
RANGE_SECRET_CODE = (1..6).freeze
|
11
|
+
EASY = { hints_total: 2, attempts_total: 15, difficulty: 'easy' }.freeze
|
12
|
+
MEDIUM = { hints_total: 1, attempts_total: 10, difficulty: 'medium' }.freeze
|
13
|
+
HELL = { hints_total: 1, attempts_total: 5, difficulty: 'hell' }.freeze
|
14
|
+
|
15
|
+
def initialize(difficulty, user)
|
16
|
+
@user = user
|
17
|
+
@difficulty = difficulty[:difficulty]
|
18
|
+
@secret_code = generator_secret_code
|
19
|
+
@attempts_total = difficulty[:attempts_total]
|
20
|
+
@hints_total = difficulty[:hints_total]
|
21
|
+
@hint = secret_code.clone.shuffle
|
22
|
+
@hints_used = 0
|
23
|
+
@attempts_used = 0
|
24
|
+
@errors = []
|
25
|
+
end
|
26
|
+
|
27
|
+
def validate_guess_input(input)
|
28
|
+
clear_errors
|
29
|
+
return errors << Message.error_guess_code unless validate_range_lenght(input, LENGTH_GUESS)
|
30
|
+
return errors << Message.error_guess_code unless check_number(transform_in_array(input), RANGE_SECRET_CODE)
|
31
|
+
end
|
32
|
+
|
33
|
+
def check_attemps
|
34
|
+
@attempts_used += 1
|
35
|
+
@attempts_used != @attempts_total
|
36
|
+
end
|
37
|
+
|
38
|
+
def check_user_input(input)
|
39
|
+
input = transform_in_array(input)
|
40
|
+
result = []
|
41
|
+
secret_arr = secret_code.clone
|
42
|
+
user_arr = input.clone
|
43
|
+
check_plus(user_arr, secret_arr, result).compact!
|
44
|
+
check_minus(user_arr, secret_arr, result)
|
45
|
+
[result].join('')
|
46
|
+
end
|
47
|
+
|
48
|
+
def hint_use
|
49
|
+
if @hints_used < @hints_total
|
50
|
+
@hints_used += 1
|
51
|
+
@hint.pop
|
52
|
+
else
|
53
|
+
clear_errors
|
54
|
+
errors << Message.error_guess_code
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_h
|
59
|
+
{
|
60
|
+
name: @user.name.capitalize,
|
61
|
+
difficulty: @difficulty,
|
62
|
+
attempts_used: @attempts_used,
|
63
|
+
attempts_total: @attempts_total,
|
64
|
+
hints_total: @hints_total,
|
65
|
+
hints_used: @hints_used
|
66
|
+
}
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def check_plus(user_arr, secret_arr, plus)
|
72
|
+
user_arr.each_index do |index|
|
73
|
+
next unless user_arr[index] == secret_arr[index]
|
74
|
+
|
75
|
+
plus << '+'
|
76
|
+
user_arr[index] = nil
|
77
|
+
secret_arr[index] = nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def check_minus(user_arr, secret_arr, minus)
|
82
|
+
user_arr.each_with_index do |number, index|
|
83
|
+
next unless secret_arr.include? number
|
84
|
+
|
85
|
+
minus << '-'
|
86
|
+
index_s = secret_arr.find_index number
|
87
|
+
user_arr[index] = nil
|
88
|
+
secret_arr[index_s] = nil
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def transform_in_array(arg)
|
93
|
+
arg.split('').map(&:to_i)
|
94
|
+
end
|
95
|
+
|
96
|
+
def clear_errors
|
97
|
+
errors.clear
|
98
|
+
end
|
99
|
+
|
100
|
+
def generator_secret_code
|
101
|
+
Array.new(LENGTH_GUESS) { Random.rand(RANGE_SECRET_CODE) }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CodebreakerRuban
|
4
|
+
class Message
|
5
|
+
class << self
|
6
|
+
def display(message)
|
7
|
+
puts message
|
8
|
+
end
|
9
|
+
|
10
|
+
def error_name_size(range)
|
11
|
+
I18n.t('errors.error_name_size', min: range.first, max: range.last)
|
12
|
+
end
|
13
|
+
|
14
|
+
def error_difficulty
|
15
|
+
puts I18n.t('errors.error_difficulty')
|
16
|
+
end
|
17
|
+
|
18
|
+
def error_guess_code
|
19
|
+
I18n.t('errors.error_guess_code')
|
20
|
+
end
|
21
|
+
|
22
|
+
def greeting
|
23
|
+
puts I18n.t(:greeting)
|
24
|
+
end
|
25
|
+
|
26
|
+
def choice_option(stats, rules, start, exit)
|
27
|
+
puts I18n.t(:choice_option, stats: stats, rules: rules, start: start, exit: exit)
|
28
|
+
end
|
29
|
+
|
30
|
+
def rules
|
31
|
+
puts I18n.t(:rules)
|
32
|
+
end
|
33
|
+
|
34
|
+
def wrong_command
|
35
|
+
puts I18n.t(:wrong_command)
|
36
|
+
end
|
37
|
+
|
38
|
+
def enter_name
|
39
|
+
puts I18n.t(:enter_name)
|
40
|
+
end
|
41
|
+
|
42
|
+
def choice_difficulty(easy, medium, hell)
|
43
|
+
puts I18n.t(:choice_difficulty, easy: easy, medium: medium, hell: hell)
|
44
|
+
end
|
45
|
+
|
46
|
+
def enter_code
|
47
|
+
puts I18n.t(:enter_code)
|
48
|
+
end
|
49
|
+
|
50
|
+
def goodbye
|
51
|
+
puts I18n.t(:goodbye)
|
52
|
+
end
|
53
|
+
|
54
|
+
def ended_attempts
|
55
|
+
puts I18n.t(:ended_attempts)
|
56
|
+
end
|
57
|
+
|
58
|
+
def save
|
59
|
+
puts I18n.t(:save)
|
60
|
+
end
|
61
|
+
|
62
|
+
def result_save
|
63
|
+
puts I18n.t(:result_save)
|
64
|
+
end
|
65
|
+
|
66
|
+
def restart
|
67
|
+
puts I18n.t(:restart)
|
68
|
+
end
|
69
|
+
|
70
|
+
def statistic_empty
|
71
|
+
puts I18n.t(:statistic_empty)
|
72
|
+
end
|
73
|
+
|
74
|
+
def show_stats(**value)
|
75
|
+
puts I18n.t(:show_stats, **value)
|
76
|
+
end
|
77
|
+
|
78
|
+
def win
|
79
|
+
puts I18n.t(:win)
|
80
|
+
end
|
81
|
+
|
82
|
+
def lose
|
83
|
+
puts I18n.t(:lose)
|
84
|
+
end
|
85
|
+
|
86
|
+
def show_secret_code(secret_code)
|
87
|
+
puts I18n.t(:show_secret_code, secret_code: secret_code)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CodebreakerRuban
|
4
|
+
class Statistic
|
5
|
+
FILE_NAME = './lib/store/store.yml'
|
6
|
+
class << self
|
7
|
+
def show_stats
|
8
|
+
data = Storage.load_storage
|
9
|
+
if data.empty?
|
10
|
+
Message.statistic_empty
|
11
|
+
else
|
12
|
+
sort_data(data).each do |value|
|
13
|
+
Message.show_stats(value)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def sort_data(items)
|
21
|
+
items.sort_by { |item| [item[:difficulty], item[:attempts_used], item[:hints_used]] }
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CodebreakerRuban
|
4
|
+
class Storage
|
5
|
+
FILE_NAME = './lib/app/store/store.yml'
|
6
|
+
class << self
|
7
|
+
def save_in_store(obj)
|
8
|
+
File.open(FILE_NAME, 'a') { |file| file.write obj.to_yaml }
|
9
|
+
end
|
10
|
+
|
11
|
+
def load_storage
|
12
|
+
store_exists? ? YAML.load_stream(File.read(FILE_NAME)) : []
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def store_exists?
|
18
|
+
File.exist?(FILE_NAME)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CodebreakerRuban
|
4
|
+
class User
|
5
|
+
include Validation
|
6
|
+
attr_accessor :errors
|
7
|
+
attr_reader :name
|
8
|
+
|
9
|
+
RANGE_NAME = (3..20).freeze
|
10
|
+
|
11
|
+
def initialize(name)
|
12
|
+
@name = name
|
13
|
+
@errors = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def validate(name)
|
17
|
+
return errors << Message.error_name_size(RANGE_NAME) unless size(name, RANGE_NAME)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CodebreakerRuban
|
4
|
+
module Validation
|
5
|
+
def check_number(user_input, range)
|
6
|
+
user_input.each { |e| break unless range.include? e.to_i }
|
7
|
+
end
|
8
|
+
|
9
|
+
def validate_range_lenght(arg, size)
|
10
|
+
arg.length == size
|
11
|
+
end
|
12
|
+
|
13
|
+
def size(arg, range)
|
14
|
+
range.include? arg.length
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/app/store/.keep
ADDED
File without changes
|
metadata
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: codebreaker_ruban
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- IRuban
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-01-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.17'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.17'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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: '3.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.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: i18n
|
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: fasterer
|
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: pry
|
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: rubocop
|
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
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-rspec
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
description: Game
|
140
|
+
email:
|
141
|
+
- moaner48@gmail.com
|
142
|
+
executables: []
|
143
|
+
extensions: []
|
144
|
+
extra_rdoc_files: []
|
145
|
+
files:
|
146
|
+
- ".circleci/config.yml"
|
147
|
+
- ".fasterer.yml"
|
148
|
+
- ".gitignore"
|
149
|
+
- ".rspec"
|
150
|
+
- ".rspec_status"
|
151
|
+
- ".rubocop.yml"
|
152
|
+
- ".ruby-gemset"
|
153
|
+
- ".ruby-version"
|
154
|
+
- ".travis.yml"
|
155
|
+
- CODE_OF_CONDUCT.md
|
156
|
+
- Gemfile
|
157
|
+
- Gemfile.lock
|
158
|
+
- LICENSE.txt
|
159
|
+
- README.md
|
160
|
+
- Rakefile
|
161
|
+
- autoload.rb
|
162
|
+
- bin/console
|
163
|
+
- bin/setup
|
164
|
+
- codebreake_ruban.gemspec
|
165
|
+
- index.rb
|
166
|
+
- lib/app/config/config_i18n.rb
|
167
|
+
- lib/app/config/locales/en.yml
|
168
|
+
- lib/app/entities/console.rb
|
169
|
+
- lib/app/entities/game.rb
|
170
|
+
- lib/app/entities/message.rb
|
171
|
+
- lib/app/entities/statistic.rb
|
172
|
+
- lib/app/entities/storage.rb
|
173
|
+
- lib/app/entities/user.rb
|
174
|
+
- lib/app/module/validation.rb
|
175
|
+
- lib/app/store/.keep
|
176
|
+
- lib/codebreaker_ruban.rb
|
177
|
+
- lib/codebreaker_ruban/version.rb
|
178
|
+
homepage: https://github.com/IRuban/codebreaker_ruban
|
179
|
+
licenses:
|
180
|
+
- MIT
|
181
|
+
metadata:
|
182
|
+
allowed_push_host: https://rubygems.org
|
183
|
+
post_install_message:
|
184
|
+
rdoc_options: []
|
185
|
+
require_paths:
|
186
|
+
- lib
|
187
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
188
|
+
requirements:
|
189
|
+
- - ">="
|
190
|
+
- !ruby/object:Gem::Version
|
191
|
+
version: '0'
|
192
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
|
+
requirements:
|
194
|
+
- - ">="
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
requirements: []
|
198
|
+
rubyforge_project:
|
199
|
+
rubygems_version: 2.7.7
|
200
|
+
signing_key:
|
201
|
+
specification_version: 4
|
202
|
+
summary: CodebreakerRuban
|
203
|
+
test_files: []
|