codebreaker_marian 0.2.8 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/codebreaker_marian/entities/data_storage.rb +14 -6
- data/lib/codebreaker_marian/entities/game.rb +1 -1
- data/lib/codebreaker_marian/entities/processor.rb +4 -10
- data/lib/codebreaker_marian/entities/statistics.rb +1 -1
- data/lib/codebreaker_marian/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 694ee8b7677b736cf19c327c069a8cd171640a5f7649a29a6eb3f60962cea4fc
|
4
|
+
data.tar.gz: 92c8e424dc63e220ba4ee2083d3f3cd5239b40620d4f22107e9f28e700a75a36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 035642cdc5e7a785c65f0367a97df452573d66b094b571af8ee7131fa902072c8edfb3491e05ce1c4f8dc8de77a4fc25b04342dcb87700255028fb0b8b20f09a
|
7
|
+
data.tar.gz: c6c1973f8ae16b86143386d501a7e02445ecdeaa56eeee3c5e2666ec3f05f9d7c9f583018e68991aa50ec6377babc5eb7ec293e4f824621d12d26b9afbda46fc
|
data/Gemfile.lock
CHANGED
@@ -3,29 +3,37 @@
|
|
3
3
|
module Codebreaker
|
4
4
|
module Entities
|
5
5
|
class DataStorage
|
6
|
-
|
6
|
+
FILE_DIRECTORY = 'database'
|
7
|
+
FILE_NAME = 'data.yml'
|
7
8
|
|
8
9
|
def create
|
9
|
-
|
10
|
-
File.
|
10
|
+
ensuring_directory_availability
|
11
|
+
File.new(File.join(FILE_DIRECTORY, FILE_NAME), 'w')
|
12
|
+
File.write(File.join(FILE_DIRECTORY, FILE_NAME), [].to_yaml)
|
11
13
|
end
|
12
14
|
|
13
15
|
def load
|
14
|
-
YAML.safe_load(File.open(FILE_NAME), [Symbol, Time]) if storage_exist?
|
16
|
+
YAML.safe_load(File.open(File.join(FILE_DIRECTORY, FILE_NAME)), [Symbol, Time]) if storage_exist?
|
15
17
|
end
|
16
18
|
|
17
19
|
def save(object)
|
18
|
-
File.open(FILE_NAME, 'w') { |file| file.write(YAML.dump(object)) }
|
20
|
+
File.open(File.join(FILE_DIRECTORY, FILE_NAME), 'w') { |file| file.write(YAML.dump(object)) }
|
19
21
|
end
|
20
22
|
|
21
23
|
def storage_exist?
|
22
|
-
File.exist?(FILE_NAME)
|
24
|
+
File.exist?(File.join(FILE_DIRECTORY, FILE_NAME))
|
23
25
|
end
|
24
26
|
|
25
27
|
def save_game_result(object)
|
26
28
|
create unless storage_exist?
|
27
29
|
save(load.push(object))
|
28
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def ensuring_directory_availability
|
35
|
+
Dir.mkdir(FILE_DIRECTORY) unless Dir.exist?(FILE_DIRECTORY)
|
36
|
+
end
|
29
37
|
end
|
30
38
|
end
|
31
39
|
end
|
@@ -5,14 +5,16 @@ module Codebreaker
|
|
5
5
|
class Processor
|
6
6
|
MATCHED_DIGIT_CHAR = '+'
|
7
7
|
UNMATCHED_DIGIT_CHAR = '-'
|
8
|
-
WRONG_DIGIT_CHAR = ''
|
8
|
+
WRONG_DIGIT_CHAR = ' '
|
9
9
|
|
10
10
|
attr_reader :guess, :code, :result
|
11
11
|
|
12
12
|
def secret_code_proc(code, guess)
|
13
13
|
@code = code.split('')
|
14
14
|
@guess = guess.split('')
|
15
|
-
handle_matched_digits.join + handle_matched_digits_with_wrong_position.join
|
15
|
+
answer = handle_matched_digits.join + handle_matched_digits_with_wrong_position.join
|
16
|
+
(code.length - answer.length).times { answer << WRONG_DIGIT_CHAR }
|
17
|
+
answer
|
16
18
|
end
|
17
19
|
|
18
20
|
private
|
@@ -34,14 +36,6 @@ module Codebreaker
|
|
34
36
|
UNMATCHED_DIGIT_CHAR
|
35
37
|
end
|
36
38
|
end
|
37
|
-
|
38
|
-
def handle_wrong_digits
|
39
|
-
guess.compact.map do |number|
|
40
|
-
next unless @code.include?(number)
|
41
|
-
|
42
|
-
WRONG_DIGIT_CHAR
|
43
|
-
end
|
44
|
-
end
|
45
39
|
end
|
46
40
|
end
|
47
41
|
end
|
@@ -5,7 +5,7 @@ module Codebreaker
|
|
5
5
|
class Statistics
|
6
6
|
def stats(list)
|
7
7
|
difficulties = list.group_by { |score| score[:difficulty] }
|
8
|
-
|
8
|
+
Game::DIFFICULTIES.keys.reverse.reduce([]) do |sorted_difficulties, difficulty_name|
|
9
9
|
if difficulties[difficulty_name]
|
10
10
|
sorted_difficulties + stats_sort(difficulties[difficulty_name])
|
11
11
|
else
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codebreaker_marian
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Marian Rebeha
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
200
200
|
- !ruby/object:Gem::Version
|
201
201
|
version: '0'
|
202
202
|
requirements: []
|
203
|
-
rubygems_version: 3.1.
|
203
|
+
rubygems_version: 3.1.4
|
204
204
|
signing_key:
|
205
205
|
specification_version: 4
|
206
206
|
summary: CodebreakerMarian app
|