icodebreaker_gem 0.3.0 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 77686e016570a9a327c2588bdfc2d36d0a09b418b58081e827b2dd671058fe6a
4
- data.tar.gz: 41071cc2d0f4fba6a345b0f9bab8cab982d45c7b91817514e1cfd3828d7865aa
3
+ metadata.gz: 4b2c433d4d680d34546db1dd48696176293335553fd1de88c7c282712f89bd43
4
+ data.tar.gz: 0ca9ab3534dc7e92c0cd5fe7aad427c2fdda33e8c2a7223d759cb0724b9617ce
5
5
  SHA512:
6
- metadata.gz: 9ac145ebb5fb673c36f6bf801d4e638d6fbc24550ccc5ee5442e65576ece7ce4332ec8fa74cc721cba6fdef4c8c1e878aacdddb4cebda5f63b03b192ae964eae
7
- data.tar.gz: d9c6fcf607a08a56433888bec900a0af213a6f3adb6cb176a5737fe34623ae1fe3e5f0ae5148dbc00d45c6d267829e47fb6af452c74f8fcf30fe57816d2095e3
6
+ metadata.gz: ac6bcdba4e9e847ac4090e044640f0b9c047f682c4959fe1b3df835bee36eb5a130181aeb7400db5f36a215007c2eb6de4a12871dbe27e7c49f6a9c640643d28
7
+ data.tar.gz: bbb8f2e92f5392c131d3124875d66ac2f0fc9ac34289718de789b5e0ce64d5a87892680fc44586572ebec45d95efeb7cae1238fbb7124c919462e889af616632
data/.rspec_status CHANGED
@@ -1,30 +1,30 @@
1
1
  example_id | status | run_time |
2
2
  ------------------------------------ | ------ | --------------- |
3
- ./spec/game_core_spec.rb[1:1] | passed | 0.00023 seconds |
4
- ./spec/game_core_spec.rb[1:2] | passed | 0.00066 seconds |
5
- ./spec/game_core_spec.rb[1:3:1] | passed | 0.00034 seconds |
6
- ./spec/game_core_spec.rb[1:4:1] | passed | 0.00053 seconds |
7
- ./spec/game_core_spec.rb[1:5:1:1] | passed | 0.00011 seconds |
8
- ./spec/game_core_spec.rb[1:5:1:2] | passed | 0.00006 seconds |
9
- ./spec/game_core_spec.rb[1:5:1:3] | passed | 0.00006 seconds |
3
+ ./spec/game_core_spec.rb[1:1] | passed | 0.00038 seconds |
4
+ ./spec/game_core_spec.rb[1:2] | passed | 0.00086 seconds |
5
+ ./spec/game_core_spec.rb[1:3:1] | passed | 0.00057 seconds |
6
+ ./spec/game_core_spec.rb[1:4:1] | passed | 0.00072 seconds |
7
+ ./spec/game_core_spec.rb[1:5:1:1] | passed | 0.00009 seconds |
8
+ ./spec/game_core_spec.rb[1:5:1:2] | passed | 0.00009 seconds |
9
+ ./spec/game_core_spec.rb[1:5:1:3] | passed | 0.00011 seconds |
10
10
  ./spec/game_core_spec.rb[1:5:1:4] | passed | 0.00006 seconds |
11
- ./spec/game_core_spec.rb[1:5:1:5] | passed | 0.00008 seconds |
12
- ./spec/game_core_spec.rb[1:5:1:6] | passed | 0.00006 seconds |
13
- ./spec/game_core_spec.rb[1:5:1:7] | passed | 0.00004 seconds |
14
- ./spec/game_core_spec.rb[1:5:2:1] | passed | 0.00005 seconds |
15
- ./spec/game_core_spec.rb[1:5:2:2] | passed | 0.00006 seconds |
11
+ ./spec/game_core_spec.rb[1:5:1:5] | passed | 0.00005 seconds |
12
+ ./spec/game_core_spec.rb[1:5:1:6] | passed | 0.00009 seconds |
13
+ ./spec/game_core_spec.rb[1:5:1:7] | passed | 0.00006 seconds |
14
+ ./spec/game_core_spec.rb[1:5:2:1] | passed | 0.00008 seconds |
15
+ ./spec/game_core_spec.rb[1:5:2:2] | passed | 0.00005 seconds |
16
16
  ./spec/game_core_spec.rb[1:5:3:1] | passed | 0.00005 seconds |
17
- ./spec/game_core_spec.rb[1:5:3:2] | passed | 0.00004 seconds |
17
+ ./spec/game_core_spec.rb[1:5:3:2] | passed | 0.00005 seconds |
18
18
  ./spec/game_core_spec.rb[1:5:3:3] | passed | 0.00004 seconds |
19
19
  ./spec/game_spec.rb[1:1:1] | passed | 0.0001 seconds |
20
- ./spec/game_spec.rb[1:2:1] | passed | 0.0002 seconds |
21
- ./spec/game_spec.rb[1:2:2] | passed | 0.00008 seconds |
22
- ./spec/game_spec.rb[1:2:3] | passed | 0.00007 seconds |
23
- ./spec/game_spec.rb[1:2:4] | passed | 0.00008 seconds |
20
+ ./spec/game_spec.rb[1:2:1] | passed | 0.00021 seconds |
21
+ ./spec/game_spec.rb[1:2:2] | passed | 0.00012 seconds |
22
+ ./spec/game_spec.rb[1:2:3] | passed | 0.0001 seconds |
23
+ ./spec/game_spec.rb[1:2:4] | passed | 0.00006 seconds |
24
24
  ./spec/game_spec.rb[1:2:5] | passed | 0.00005 seconds |
25
- ./spec/game_spec.rb[1:3:1] | passed | 0.00034 seconds |
25
+ ./spec/game_spec.rb[1:3:1] | passed | 0.00051 seconds |
26
26
  ./spec/game_spec.rb[1:3:2] | passed | 0.00017 seconds |
27
27
  ./spec/game_spec.rb[1:3:3] | passed | 0.00014 seconds |
28
- ./spec/game_spec.rb[1:4:1] | passed | 0.00014 seconds |
29
- ./spec/game_spec.rb[1:5:1] | passed | 0.00104 seconds |
28
+ ./spec/game_spec.rb[1:4:1] | passed | 0.00376 seconds |
29
+ ./spec/game_spec.rb[1:5:1] | passed | 0.00123 seconds |
30
30
  ./spec/icodebreaker_gem_spec.rb[1:1] | passed | 0.00007 seconds |
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- icodebreaker_gem (0.3.0)
4
+ icodebreaker_gem (0.3.4)
5
5
  rake (~> 13.0)
6
6
 
7
7
  GEM
@@ -10,11 +10,14 @@ GEM
10
10
  ast (2.4.2)
11
11
  coderay (1.1.3)
12
12
  colorize (0.8.1)
13
+ concurrent-ruby (1.1.9)
13
14
  diff-lcs (1.4.4)
14
15
  docile (1.4.0)
15
16
  fasterer (0.9.0)
16
17
  colorize (~> 0.7)
17
18
  ruby_parser (>= 3.14.1)
19
+ i18n (1.8.10)
20
+ concurrent-ruby (~> 1.0)
18
21
  method_source (1.0.0)
19
22
  parallel (1.21.0)
20
23
  parser (3.0.2.0)
@@ -66,12 +69,13 @@ PLATFORMS
66
69
  x86_64-linux
67
70
 
68
71
  DEPENDENCIES
69
- fasterer
72
+ fasterer (>= 0.9.0)
73
+ i18n
70
74
  icodebreaker_gem!
71
- pry
75
+ pry (>= 0.14.1)
72
76
  rspec (~> 3.0)
73
77
  rubocop (~> 1.7)
74
- simplecov
78
+ simplecov (>= 0.21.2)
75
79
 
76
80
  BUNDLED WITH
77
81
  2.2.26
@@ -0,0 +1,4 @@
1
+ en:
2
+ message:
3
+ lose: "The game is over."
4
+ no_hints: "No hints left."
data/lib/config.rb CHANGED
@@ -1,7 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'yaml'
4
-
4
+ require 'i18n'
5
+ require 'psych'
5
6
  require_relative 'modules/validation'
6
7
  require_relative 'modules/storage'
7
8
 
@@ -9,4 +10,5 @@ require_relative 'game_core'
9
10
  require_relative 'game'
10
11
  require_relative 'icodebreaker_gem/version'
11
12
  require_relative 'icodebreaker_gem'
12
- require_relative 'constants'
13
+
14
+ I18n.load_path << Dir[['config', 'locales', '**', '*.yml'].join('/')]
data/lib/game.rb CHANGED
@@ -5,7 +5,24 @@ module IcodebreakerGem
5
5
  include Validation
6
6
  include Storage
7
7
 
8
- attr_reader :name, :difficulty, :attempts_used, :hints_used, :status, :result
8
+ STATUS = %i[go_on over].freeze
9
+ RESULT = %i[win lose].freeze
10
+ DIFFICULTIES = {
11
+ easy: {
12
+ attempts_total: 15,
13
+ hints_total: 2
14
+ },
15
+ medium: {
16
+ attempts_total: 10,
17
+ hints_total: 1
18
+ },
19
+ hell: {
20
+ attempts_total: 5,
21
+ hints_total: 1
22
+ }
23
+ }.freeze
24
+
25
+ attr_accessor :name, :difficulty, :attempts_used, :hints_used, :status, :result, :code
9
26
 
10
27
  def initialize(name = 'User1', difficulty = :easy, secret = GameCore.random)
11
28
  validate_name name
@@ -40,19 +57,19 @@ module IcodebreakerGem
40
57
  check_lose
41
58
  answer
42
59
  when :over
43
- 'The game is over.'
60
+ I18n.t('message.lose')
44
61
  end
45
62
  end
46
63
 
47
64
  def hint
48
65
  case @status
49
66
  when :go_on
50
- return 'No hints left.' if @hints_used >= hints_total
67
+ return I18n.t('message.no_hints') if @hints_used >= hints_total
51
68
 
52
69
  @hints_used += 1
53
70
  @code.hint
54
71
  when :over
55
- 'The game is over.'
72
+ I18n.t('message.lose')
56
73
  end
57
74
  end
58
75
 
data/lib/game_core.rb CHANGED
@@ -13,7 +13,7 @@ module IcodebreakerGem
13
13
 
14
14
  def compare(guess)
15
15
  return '++++' if @secret == guess
16
- return '' if (@secret.chars & guess.chars).blank?
16
+ return '' if (@secret.chars & guess.chars).empty?
17
17
 
18
18
  pluses1, minuses1 = pluses_and_minuses(@secret, guess)
19
19
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IcodebreakerGem
4
- VERSION = '0.3.0'
4
+ VERSION = '0.3.4'
5
5
  end
@@ -2,4 +2,4 @@
2
2
 
3
3
  require_relative 'icodebreaker_gem/version'
4
4
  require_relative 'config'
5
- module IcodebreakerGem end
5
+ module IcodebreakerGem end
@@ -4,18 +4,21 @@ module IcodebreakerGem
4
4
  module Storage
5
5
  DATA_FILE = 'codebreakers.yml'
6
6
  STORAGE_PATH = './storage/'
7
- def save_storage(game)
8
- create_storage
9
- games = load_storage
10
- games << game
11
- File.open(data_path, 'w') do |file|
12
- YAML.dump(games, file)
13
- end
14
- end
7
+
15
8
  class << self
9
+
10
+ def save_storage
11
+ create_storage
12
+ games = load_storage
13
+ games << game_data
14
+ File.open(data_path, 'w') do |file|
15
+ YAML.dump(games, file)
16
+ end
17
+
18
+ end
16
19
  def load_storage
17
20
  create_storage
18
- YAML.load(File.read(data_path)) || []
21
+ YAML.safe_load(File.read(data_path)) || []
19
22
  end
20
23
 
21
24
  def sort_codebreakers
@@ -2,12 +2,15 @@
2
2
 
3
3
  module IcodebreakerGem
4
4
  module Validation
5
+ USERNAME = /^[0-9a-zA-Z]{3,20}$/.freeze
6
+ CODE = /^[1-6]{4}$/.freeze
7
+
5
8
  def validate_name(name)
6
- raise ArgumentError, 'Incorrect username' unless name.to_s.match?(/^[0-9a-zA-Z]{3,20}$/)
9
+ raise ArgumentError, 'Incorrect username' unless name.to_s.match?(USERNAME)
7
10
  end
8
11
 
9
12
  def validate_code(code)
10
- raise ArgumentError, 'Incorrect code' unless code.to_s.match?(/^[1-6]{4}$/)
13
+ raise ArgumentError, 'Incorrect code' unless code.to_s.match?(CODE)
11
14
  end
12
15
 
13
16
  def validate_difficulty(difficulty)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: icodebreaker_gem
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - JohnnyGsy
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-09-29 00:00:00.000000000 Z
11
+ date: 2021-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -26,6 +26,20 @@ dependencies:
26
26
  version: '13.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: fasterer
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: i18n
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
@@ -44,14 +58,14 @@ dependencies:
44
58
  requirements:
45
59
  - - ">="
46
60
  - !ruby/object:Gem::Version
47
- version: '0'
61
+ version: 0.14.1
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
- version: '0'
68
+ version: 0.14.1
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +100,14 @@ dependencies:
86
100
  requirements:
87
101
  - - ">="
88
102
  - !ruby/object:Gem::Version
89
- version: '0'
103
+ version: 0.21.2
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - ">="
95
109
  - !ruby/object:Gem::Version
96
- version: '0'
110
+ version: 0.21.2
97
111
  description: Guess the secret code
98
112
  email:
99
113
  - vanstrelok@gmail.com
@@ -115,8 +129,8 @@ files:
115
129
  - Rakefile
116
130
  - bin/console
117
131
  - bin/setup
132
+ - config/locales/en.yml
118
133
  - lib/config.rb
119
- - lib/constants.rb
120
134
  - lib/game.rb
121
135
  - lib/game_core.rb
122
136
  - lib/icodebreaker_gem.rb
data/lib/constants.rb DELETED
@@ -1,20 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module IcodebreakerGem
4
- STATUS = %i[go_on over].freeze
5
- RESULT = %i[win lose].freeze
6
- DIFFICULTIES = {
7
- easy: {
8
- attempts_total: 15,
9
- hints_total: 2
10
- },
11
- medium: {
12
- attempts_total: 10,
13
- hints_total: 1
14
- },
15
- hell: {
16
- attempts_total: 5,
17
- hints_total: 1
18
- }
19
- }.freeze
20
- end