codebreaker_kirill 1.3.0 → 1.3.3
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/code_generator.rb +1 -1
- data/lib/codebreaker_kirill/game.rb +2 -2
- data/lib/codebreaker_kirill/guess_handler.rb +3 -3
- data/lib/codebreaker_kirill/user.rb +3 -3
- data/lib/codebreaker_kirill/validations.rb +5 -5
- data/lib/codebreaker_kirill/version.rb +1 -1
- data/lib/codebreaker_kirill.rb +3 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd8e9ef96c5584a34b2ac7986f2405468d91be72b4e7575bfbab1723a2252fc1
|
4
|
+
data.tar.gz: 8d011efcb4905860d969d48929922997a2298953ee66b0a249b17ca99168d7ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52e0e98384554272f56815c482e2779b0e1a0c33b436b9f47113460cf7826129fdb5d43840ec424c2ee1f54feeb497256a9b7699bd063acb74b8a5bdd3877162
|
7
|
+
data.tar.gz: 851384f6e97f45855d6db4ae58a6fa730bbfc3622d96b8b9d4d0393efcdcba5949966a4bedbb12ce5fa110d6e74c47cfd0aab359fb48c714100a195d2612c015
|
@@ -9,7 +9,7 @@ module CodebreakerKirill
|
|
9
9
|
attr_reader :user
|
10
10
|
|
11
11
|
def initialize(user)
|
12
|
-
@secret_code = CodeGenerator.call
|
12
|
+
@secret_code = CodebreakerKirill::CodeGenerator.call
|
13
13
|
@user = user
|
14
14
|
end
|
15
15
|
|
@@ -23,7 +23,7 @@ module CodebreakerKirill
|
|
23
23
|
def respond_to_guess(input)
|
24
24
|
@user.attempts_used += 1
|
25
25
|
status = status(input, @secret_code)
|
26
|
-
resolved_code = GuessHandler.new(input, @secret_code).call
|
26
|
+
resolved_code = CodebreakerKirill::GuessHandler.new(input, @secret_code).call
|
27
27
|
return { status: status, secret_code: @secret_code } if status == 'loss'
|
28
28
|
|
29
29
|
{ status: status, response: resolved_code, secret_code: @secret_code }
|
@@ -7,7 +7,7 @@ module CodebreakerKirill
|
|
7
7
|
include Settings
|
8
8
|
|
9
9
|
def initialize(input, code)
|
10
|
-
Validations.validate_guess(input)
|
10
|
+
CodebreakerKirill::Validations.validate_guess(input)
|
11
11
|
@input = input.each_char.map(&:to_i)
|
12
12
|
@code = code.clone
|
13
13
|
@result = []
|
@@ -23,7 +23,7 @@ module CodebreakerKirill
|
|
23
23
|
@input.each_index do |index|
|
24
24
|
next unless @input[index] == @code[index]
|
25
25
|
|
26
|
-
@result << Settings::POSITIVE_RESPONSE
|
26
|
+
@result << CodebreakerKirill::Settings::POSITIVE_RESPONSE
|
27
27
|
@input[index], @code[index] = nil
|
28
28
|
end
|
29
29
|
end
|
@@ -32,7 +32,7 @@ module CodebreakerKirill
|
|
32
32
|
@input.each_with_index do |value, _index|
|
33
33
|
next unless !value.nil? && @code.include?(value)
|
34
34
|
|
35
|
-
@result << Settings::NEGATIVE_RESPONSE
|
35
|
+
@result << CodebreakerKirill::Settings::NEGATIVE_RESPONSE
|
36
36
|
@input[@input.find_index(value)], @code[@code.find_index(value)] = nil
|
37
37
|
end
|
38
38
|
end
|
@@ -13,14 +13,14 @@ module CodebreakerKirill
|
|
13
13
|
validation(name, difficulty)
|
14
14
|
@difficulty = difficulty
|
15
15
|
@name = name
|
16
|
-
@level = Settings::DIFFICULTY[@difficulty]
|
16
|
+
@level = CodebreakerKirill::Settings::DIFFICULTY[@difficulty]
|
17
17
|
@attempts_used = 0
|
18
18
|
@hints_used = 0
|
19
19
|
end
|
20
20
|
|
21
21
|
def validation(name, difficulty)
|
22
|
-
Validations.validate_name(name)
|
23
|
-
Validations.validate_difficulty(difficulty)
|
22
|
+
CodebreakerKirill::Validations.validate_name(name)
|
23
|
+
CodebreakerKirill::Validations.validate_difficulty(difficulty)
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -9,21 +9,21 @@ module CodebreakerKirill
|
|
9
9
|
def self.validate_name(name)
|
10
10
|
raise "Name shouldn't be empty" if name.empty?
|
11
11
|
raise 'Name should be string' if name.class != String
|
12
|
-
raise 'Name should be at least 3 characters long' if name.length < Settings::NAME_MIN_LENGTH
|
12
|
+
raise 'Name should be at least 3 characters long' if name.length < CodebreakerKirill::Settings::NAME_MIN_LENGTH
|
13
13
|
raise "Name shouldn't be more than 20 characters long" if name.length > Settings::NAME_MAX_LENGTH
|
14
14
|
end
|
15
15
|
|
16
16
|
def self.validate_guess(guess)
|
17
17
|
raise "Guess shouldn't be empty" if guess.empty?
|
18
|
-
raise
|
19
|
-
raise 'Guess
|
18
|
+
raise 'Guess should be 4 characters' if guess.length < CodebreakerKirill::Settings::GUESS_LENGTH
|
19
|
+
raise 'Guess shouldnt be more than 4 characters long' if guess.length > CodebreakerKirill::Settings::GUESS_LENGTH
|
20
20
|
end
|
21
21
|
|
22
22
|
def self.validate_difficulty(difficulty)
|
23
23
|
raise "Input shouldn't be empty" if difficulty.empty?
|
24
|
-
return if Settings::DIFFICULTY.keys.include?(difficulty)
|
24
|
+
return if CodebreakerKirill::Settings::DIFFICULTY.keys.include?(difficulty)
|
25
25
|
|
26
|
-
raise "You should enter one of the following options: #{Settings::DIFFICULTY.keys.join(', ')}"
|
26
|
+
raise "You should enter one of the following options: #{CodebreakerKirill::Settings::DIFFICULTY.keys.join(', ')}"
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
data/lib/codebreaker_kirill.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'codebreaker_kirill/settings'
|
4
|
-
require_relative 'codebreaker_kirill/code_generator'
|
5
4
|
require_relative 'codebreaker_kirill/validations'
|
6
5
|
require_relative 'codebreaker_kirill/guess_handler'
|
7
6
|
require_relative 'codebreaker_kirill/user'
|
8
7
|
require_relative 'codebreaker_kirill/game'
|
9
8
|
require_relative 'codebreaker_kirill/stats'
|
9
|
+
|
10
|
+
module CodebreakerKirill
|
11
|
+
end
|