codebreaker_kirill 1.3.3 → 1.3.6

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