icodebreaker_gem 0.1.0 → 0.3.0

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: 9d9622a8db1d947dc547773bc5dcbf654bc0ad1c18b988ca794334b026a3ec00
4
- data.tar.gz: 38735f987b4667dcfb146b1b73242a4fd6a3c1e4160a6cf7b760c6fb9d36e4cf
3
+ metadata.gz: 77686e016570a9a327c2588bdfc2d36d0a09b418b58081e827b2dd671058fe6a
4
+ data.tar.gz: 41071cc2d0f4fba6a345b0f9bab8cab982d45c7b91817514e1cfd3828d7865aa
5
5
  SHA512:
6
- metadata.gz: dbf0773f9a7b463a27645be4ea7773d238559bd1c02dd2ead8c28f680a04762a7f28d098123b928c0503c472f79cd417b7719640bcfb20ee844662cc5d69d7e6
7
- data.tar.gz: 25233a18a435faf6ad2dbd9a776acefea3acfbbc7ea0ee7b4cbe1b7b34642588ecbd66aec9de2be18b659a57d0a2ffe2292ed6159647e905f7d90899f0b21433
6
+ metadata.gz: 9ac145ebb5fb673c36f6bf801d4e638d6fbc24550ccc5ee5442e65576ece7ce4332ec8fa74cc721cba6fdef4c8c1e878aacdddb4cebda5f63b03b192ae964eae
7
+ data.tar.gz: d9c6fcf607a08a56433888bec900a0af213a6f3adb6cb176a5737fe34623ae1fe3e5f0ae5148dbc00d45c6d267829e47fb6af452c74f8fcf30fe57816d2095e3
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.00038 seconds |
4
- ./spec/game_core_spec.rb[1:2] | passed | 0.00089 seconds |
5
- ./spec/game_core_spec.rb[1:3:1] | passed | 0.00064 seconds |
6
- ./spec/game_core_spec.rb[1:4:1] | passed | 0.00078 seconds |
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
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.0001 seconds |
9
- ./spec/game_core_spec.rb[1:5:1:3] | passed | 0.00011 seconds |
10
- ./spec/game_core_spec.rb[1:5:1:4] | passed | 0.00015 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.00007 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 |
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
13
  ./spec/game_core_spec.rb[1:5:1:7] | passed | 0.00004 seconds |
14
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.00005 seconds |
15
+ ./spec/game_core_spec.rb[1:5:2:2] | passed | 0.00006 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.00006 seconds |
17
+ ./spec/game_core_spec.rb[1:5:3:2] | passed | 0.00004 seconds |
18
18
  ./spec/game_core_spec.rb[1:5:3:3] | passed | 0.00004 seconds |
19
- ./spec/game_spec.rb[1:1:1] | passed | 0.00012 seconds |
20
- ./spec/game_spec.rb[1:2:1] | passed | 0.00025 seconds |
21
- ./spec/game_spec.rb[1:2:2] | passed | 0.00007 seconds |
22
- ./spec/game_spec.rb[1:2:3] | passed | 0.00008 seconds |
23
- ./spec/game_spec.rb[1:2:4] | passed | 0.00007 seconds |
24
- ./spec/game_spec.rb[1:2:5] | passed | 0.00008 seconds |
25
- ./spec/game_spec.rb[1:3:1] | passed | 0.00058 seconds |
26
- ./spec/game_spec.rb[1:3:2] | passed | 0.0002 seconds |
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 |
24
+ ./spec/game_spec.rb[1:2:5] | passed | 0.00005 seconds |
25
+ ./spec/game_spec.rb[1:3:1] | passed | 0.00034 seconds |
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.00012 seconds |
29
- ./spec/game_spec.rb[1:5:1] | passed | 0.0014 seconds |
30
- ./spec/icodebreaker_gem_spec.rb[1:1] | passed | 0.0001 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 |
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.1.0)
4
+ icodebreaker_gem (0.3.0)
5
5
  rake (~> 13.0)
6
6
 
7
7
  GEM
data/lib/config.rb CHANGED
@@ -1,13 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
-
4
3
  require 'yaml'
5
4
 
6
- require 'modules/validation'
7
- require 'modules/storage'
5
+ require_relative 'modules/validation'
6
+ require_relative 'modules/storage'
8
7
 
9
- require 'game_core'
10
- require 'game'
11
- require 'icodebreaker_gem/version'
12
- require 'icodebreaker_gem'
13
- require 'constants'
8
+ require_relative 'game_core'
9
+ require_relative 'game'
10
+ require_relative 'icodebreaker_gem/version'
11
+ require_relative 'icodebreaker_gem'
12
+ require_relative 'constants'
data/lib/game_core.rb CHANGED
@@ -4,19 +4,16 @@ module IcodebreakerGem
4
4
  class GameCore
5
5
  include Validation
6
6
 
7
- attr_reader :secret
8
-
9
7
  def initialize(secret)
10
8
  validate_code secret
11
9
 
12
10
  @secret = secret.to_s
13
- @shuffle = @secret.each_char.to_a.shuffle
14
- @hint_idx = 0
11
+ @shuffle = @secret.chars.shuffle
15
12
  end
16
13
 
17
14
  def compare(guess)
18
15
  return '++++' if @secret == guess
19
- return '' if (@secret.each_char.to_a & guess.each_char.to_a).empty?
16
+ return '' if (@secret.chars & guess.chars).blank?
20
17
 
21
18
  pluses1, minuses1 = pluses_and_minuses(@secret, guess)
22
19
 
@@ -26,24 +23,21 @@ module IcodebreakerGem
26
23
  end
27
24
 
28
25
  def hint
29
- result = @shuffle[@hint_idx]
30
- @hint_idx += 1
31
- @hint_idx = 0 if @hint_idx >= @shuffle.size
32
- result
26
+ @shuffle.pop
33
27
  end
34
28
 
35
29
  def self.random
36
- (0..3).map { rand(1..6) }.map(&:to_s).join
30
+ (0..3).map { rand(1..6) }.join
37
31
  end
38
32
 
39
33
  private
40
34
 
41
- def pluses_and_minuses(word1, word2)
35
+ def pluses_and_minuses(guess_secret, secret_guess)
42
36
  pluses = minuses = 0
43
- word1.each_char.to_a.each_index do |index|
44
- if word2[index] == word1[index]
37
+ guess_secret.chars.each_index do |index|
38
+ if secret_guess[index] == guess_secret[index]
45
39
  pluses += 1
46
- elsif word2.include? word1[index]
40
+ elsif secret_guess.include? guess_secret[index]
47
41
  minuses += 1
48
42
  end
49
43
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IcodebreakerGem
4
- VERSION = '0.1.0'
4
+ VERSION = '0.3.0'
5
5
  end
@@ -1,8 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'icodebreaker_gem/version'
4
-
5
- module IcodebreakerGem
6
- class Error < StandardError; end
7
- # Your code goes here...
8
- end
4
+ require_relative 'config'
5
+ module IcodebreakerGem end
@@ -12,27 +12,28 @@ module IcodebreakerGem
12
12
  YAML.dump(games, file)
13
13
  end
14
14
  end
15
+ class << self
16
+ def load_storage
17
+ create_storage
18
+ YAML.load(File.read(data_path)) || []
19
+ end
15
20
 
16
- def load_storage
17
- create_storage
18
- YAML.load(File.read(data_path)) || []
19
- end
20
-
21
- def sort_codebreakers
22
- load_storage.sort_by do |statistic|
23
- [statistic[:attempts_total], statistic[:attempts_used], statistic[:hints_used]]
21
+ def sort_codebreakers
22
+ load_storage.sort_by do |statistic|
23
+ [statistic[:attempts_total], statistic[:attempts_used], statistic[:hints_used]]
24
+ end
24
25
  end
25
- end
26
26
 
27
- private
27
+ private
28
28
 
29
- def data_path
30
- STORAGE_PATH + DATA_FILE
31
- end
29
+ def data_path
30
+ STORAGE_PATH + DATA_FILE
31
+ end
32
32
 
33
- def create_storage
34
- Dir.mkdir(STORAGE_PATH) unless File.exist?(STORAGE_PATH)
35
- File.open(data_path, 'w') unless File.exist?(data_path)
33
+ def create_storage
34
+ Dir.mkdir(STORAGE_PATH) unless File.exist?(STORAGE_PATH)
35
+ File.open(data_path, 'w') unless File.exist?(data_path)
36
+ end
36
37
  end
37
38
  end
38
39
  end
File without changes
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.1.0
4
+ version: 0.3.0
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-27 00:00:00.000000000 Z
11
+ date: 2021-09-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -124,6 +124,7 @@ files:
124
124
  - lib/modules/storage.rb
125
125
  - lib/modules/validation.rb
126
126
  - reek.yml
127
+ - storage/codebreakers.yml
127
128
  homepage: https://github.com/JohnnyGsy/icodebreaker_gem
128
129
  licenses:
129
130
  - MIT