codebreaker_kirill 0.2.17 → 0.3.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.
- checksums.yaml +4 -4
- data/lib/codebreaker_kirill/autoload.rb +6 -2
- data/lib/codebreaker_kirill/code_generator.rb +0 -4
- data/lib/codebreaker_kirill/game.rb +2 -9
- data/lib/codebreaker_kirill/guess_handler.rb +16 -3
- data/lib/codebreaker_kirill/settings.rb +2 -2
- data/lib/codebreaker_kirill/user.rb +11 -7
- data/lib/codebreaker_kirill/validations.rb +7 -7
- data/lib/codebreaker_kirill/version.rb +1 -1
- data/lib/codebreaker_kirill.rb +3 -0
- metadata +2 -3
- data/lib/codebreaker_kirill/stats.yml +0 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3f6ed248059b392d1c1f939faa4c76261e309db02dc5cec24bf76150615c388
|
4
|
+
data.tar.gz: 4693fb4f735da3bf31dbb6f7d9367162252197ee6e0d6c9d5a194b875016c112
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2ae118680b9e3ce2533aca51ca87a9d05c330cdad3e8679a7342309d9a98f44a59d6e5a5f3beb78a80d9896121dc2051cbf53fa92514ff59829668df0abf2115
|
7
|
+
data.tar.gz: b39edda7c5b41000c1a2a1d19cb6df6324ff66af93e44f52142e40637b9fae908b1b8868e32cebd333b4545366b7680e1f89b1b04bb72ab27f372ff34b7cae54
|
@@ -1,18 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require_relative 'validations'
|
5
|
-
require_relative 'guess_handler'
|
6
|
-
require_relative 'user'
|
7
|
-
require_relative 'settings'
|
3
|
+
require_relative 'autoload'
|
8
4
|
require_relative 'code_generator'
|
9
|
-
require_relative '
|
5
|
+
require_relative 'user'
|
10
6
|
|
11
7
|
class Game
|
12
|
-
include GuessHandler
|
13
|
-
include Validations
|
14
8
|
include CodeGenerator
|
15
|
-
include Settings
|
16
9
|
|
17
10
|
attr_reader :secret_code, :user
|
18
11
|
|
@@ -1,9 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
require_relative 'autoload'
|
4
|
+
require_relative 'game'
|
5
|
+
|
6
|
+
class GuessHandler
|
4
7
|
def respond_to_guess(game, input, code)
|
5
|
-
|
6
|
-
return game.give_a_hint if input ==
|
8
|
+
validation(input)
|
9
|
+
return game.give_a_hint if input == 'hint'
|
10
|
+
|
7
11
|
@result = []
|
8
12
|
@code_clone = code.clone
|
9
13
|
@numbers = input.split('').map(&:to_i)
|
@@ -37,4 +41,13 @@ module GuessHandler
|
|
37
41
|
end.sort
|
38
42
|
end
|
39
43
|
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def validation(input)
|
48
|
+
Validations.validate_guess(input)
|
49
|
+
rescue StandardError => e
|
50
|
+
puts e.message
|
51
|
+
nil
|
52
|
+
end
|
40
53
|
end
|
@@ -1,20 +1,24 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
3
|
+
require_relative 'autoload'
|
4
4
|
require_relative 'settings'
|
5
5
|
|
6
6
|
class User
|
7
|
-
include Validations
|
8
|
-
include Settings
|
9
|
-
|
10
7
|
attr_reader :name, :difficulty, :attempts, :hints
|
11
8
|
|
12
9
|
def initialize(name, difficulty)
|
13
|
-
|
14
|
-
validate_difficulty(difficulty)
|
10
|
+
validation(name, difficulty)
|
15
11
|
@name = name
|
16
|
-
@difficulty = Settings::
|
12
|
+
@difficulty = Settings::DIFFICULTY[difficulty]
|
17
13
|
@attempts = { all: @difficulty[:attempts], used: 0 }
|
18
14
|
@hints = { all: @difficulty[:hints], used: 0 }
|
19
15
|
end
|
16
|
+
|
17
|
+
def validation(_input)
|
18
|
+
Validations.validate_name(name)
|
19
|
+
Validations.validate_difficulty(difficulty)
|
20
|
+
rescue StandardError => e
|
21
|
+
puts e.message
|
22
|
+
nil
|
23
|
+
end
|
20
24
|
end
|
@@ -1,20 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
def validate_name(name)
|
3
|
+
class Validations
|
4
|
+
def self.validate_name(name)
|
5
5
|
raise "Name shouldn't be empty" if name.empty?
|
6
6
|
raise 'Name should be string' if name.class != String
|
7
7
|
raise 'Name should be at least 3 characters long' if name.length < 3
|
8
8
|
raise "Name shouldn't be more than 20 characters long" if name.length > 20
|
9
9
|
end
|
10
10
|
|
11
|
-
def validate_guess(guess)
|
12
|
-
raise "
|
13
|
-
raise '
|
14
|
-
raise '
|
11
|
+
def self.validate_guess(guess)
|
12
|
+
raise "Guess shouldn't be empty" if guess.empty?
|
13
|
+
raise 'Guess should be at least 3 characters long' if guess.length < 4
|
14
|
+
raise 'Guess shouldn\'t be more than 4 characters long' if guess.length > 4
|
15
15
|
end
|
16
16
|
|
17
|
-
def validate_difficulty(difficulty)
|
17
|
+
def self.validate_difficulty(difficulty)
|
18
18
|
raise "Input shouldn't be empty" if difficulty.empty?
|
19
19
|
return if difficulty.match?(/easy|medium|hell/)
|
20
20
|
|
data/lib/codebreaker_kirill.rb
CHANGED
@@ -3,6 +3,9 @@
|
|
3
3
|
require_relative 'codebreaker_kirill/version'
|
4
4
|
require_relative 'codebreaker_kirill/game'
|
5
5
|
require_relative 'codebreaker_kirill/user'
|
6
|
+
require_relative 'codebreaker_kirill/guess_handler'
|
7
|
+
require_relative 'codebreaker_kirill/settings'
|
8
|
+
require_relative 'codebreaker_kirill/stats'
|
6
9
|
|
7
10
|
module CodebreakerKirill
|
8
11
|
class Error < StandardError; end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreaker_kirill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kirill Dudchenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-08-
|
11
|
+
date: 2022-08-19 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -32,7 +32,6 @@ files:
|
|
32
32
|
- lib/codebreaker_kirill/guess_handler.rb
|
33
33
|
- lib/codebreaker_kirill/settings.rb
|
34
34
|
- lib/codebreaker_kirill/stats.rb
|
35
|
-
- lib/codebreaker_kirill/stats.yml
|
36
35
|
- lib/codebreaker_kirill/user.rb
|
37
36
|
- lib/codebreaker_kirill/validations.rb
|
38
37
|
- lib/codebreaker_kirill/version.rb
|
@@ -1,34 +0,0 @@
|
|
1
|
-
---
|
2
|
-
- !ruby/object:User
|
3
|
-
name: dima
|
4
|
-
difficulty:
|
5
|
-
:attempts: 10
|
6
|
-
:hints: 1
|
7
|
-
attempts:
|
8
|
-
:all: 10
|
9
|
-
:used: 0
|
10
|
-
hints:
|
11
|
-
:all: 1
|
12
|
-
:used: 0
|
13
|
-
- !ruby/object:User
|
14
|
-
name: stacy
|
15
|
-
difficulty:
|
16
|
-
:attempts: 5
|
17
|
-
:hints: 1
|
18
|
-
attempts:
|
19
|
-
:all: 5
|
20
|
-
:used: 0
|
21
|
-
hints:
|
22
|
-
:all: 1
|
23
|
-
:used: 0
|
24
|
-
- !ruby/object:User
|
25
|
-
name: kirill
|
26
|
-
difficulty:
|
27
|
-
:attempts: 5
|
28
|
-
:hints: 1
|
29
|
-
attempts:
|
30
|
-
:all: 5
|
31
|
-
:used: 0
|
32
|
-
hints:
|
33
|
-
:all: 1
|
34
|
-
:used: 0
|