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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ca2a9e18040569430affe912a91553e4b75111ac9e269b0c88a536a9ba9a3fe1
4
- data.tar.gz: 3c4b4c50a303aba79aa4191f9c7fd7795acae84fa0eab6fa59ffa611cfec7e7b
3
+ metadata.gz: d3f6ed248059b392d1c1f939faa4c76261e309db02dc5cec24bf76150615c388
4
+ data.tar.gz: 4693fb4f735da3bf31dbb6f7d9367162252197ee6e0d6c9d5a194b875016c112
5
5
  SHA512:
6
- metadata.gz: e332c34663d075529458200c45e368068d2cd11763f24599bcd07a91faef64a4776b5cc1f2a8747223f2a72b840ec033da61fe43dcc68d2562bf965e2fbab139
7
- data.tar.gz: f40c63b83eb5f3b67bdc103efe9c64e822db52efe3c8cb8542997008385714108d28df8bd5fee84ca2a0bf706f0e386ab84e30b4f5e26887077ce73fdbc03daa
6
+ metadata.gz: 2ae118680b9e3ce2533aca51ca87a9d05c330cdad3e8679a7342309d9a98f44a59d6e5a5f3beb78a80d9896121dc2051cbf53fa92514ff59829668df0abf2115
7
+ data.tar.gz: b39edda7c5b41000c1a2a1d19cb6df6324ff66af93e44f52142e40637b9fae908b1b8868e32cebd333b4545366b7680e1f89b1b04bb72ab27f372ff34b7cae54
@@ -1,4 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'game'
4
- require_relative 'user'
3
+ require 'yaml'
4
+ require_relative 'validations'
5
+ require_relative 'guess_handler'
6
+ require_relative 'settings'
7
+ require_relative 'code_generator'
8
+ require_relative 'stats'
@@ -1,10 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'settings'
4
-
5
3
  module CodeGenerator
6
- include Settings
7
-
8
4
  def self.call
9
5
  Array.new(Settings::CODE_LENGTH) { rand(Settings::RANDOM_RANGE) }
10
6
  end
@@ -1,18 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'yaml'
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 'stats'
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
- module GuessHandler
3
+ require_relative 'autoload'
4
+ require_relative 'game'
5
+
6
+ class GuessHandler
4
7
  def respond_to_guess(game, input, code)
5
- validate_guess(input)
6
- return game.give_a_hint if input == "hint"
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,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Settings
4
- LEVEL = {
3
+ class Settings
4
+ DIFFICULTY = {
5
5
  'easy' => { attempts: 15, hints: 2 },
6
6
  'medium' => { attempts: 10, hints: 1 },
7
7
  'hell' => { attempts: 5, hints: 1 }
@@ -1,20 +1,24 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'validations'
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
- validate_name(name)
14
- validate_difficulty(difficulty)
10
+ validation(name, difficulty)
15
11
  @name = name
16
- @difficulty = Settings::LEVEL[difficulty]
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
- module Validations
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 "Name shouldn't be empty" if guess.empty?
13
- raise 'Name should be at least 3 characters long' if guess.length < 4
14
- raise 'Name shouldn\'t be more than 4 characters long' if guess.length > 4
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
 
@@ -3,5 +3,5 @@
3
3
  require_relative 'game'
4
4
 
5
5
  module CodebreakerKirill
6
- VERSION = '0.2.17'
6
+ VERSION = '0.3.0'
7
7
  end
@@ -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.2.17
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-18 00:00:00.000000000 Z
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