codebreaker-Bulatkin 0.1.0 → 0.1.1

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: 650cb47ef623f29bf16ac29db47c79152674e0ad0927cc985c441af3213f526e
4
- data.tar.gz: 24ec2b0c64f5fa568cc6eabeaf318e290d08403258b782159fe8992eb90e824f
3
+ metadata.gz: a3c4436b52cd092b50d56261fd4e89105673c713b8d852afbb5516c3375d1759
4
+ data.tar.gz: 19113c0674f6871613e15958771f5146b7defc44c2595c4a54c1efcab0f7a4cc
5
5
  SHA512:
6
- metadata.gz: 1c87325aac46da9c0815e4b0d24aba5245f4f5ffc834df069218c4f134f79e047bf2165c70b41563477b4d6cd89823f81deb02d95d8e368069f235843a54b374
7
- data.tar.gz: 0b825164cf97721a3c34767ccc06c9ab39084c28ba980588d9596b5051cbe6a592c29fbffa197ee02d2f45531c291039c4dcd9e11719692175ffaf4121a3f0da
6
+ metadata.gz: f59057c66e41b47a073ce0ab4faa1f24db127c8e36800b38742b839212aaa4c460d59e02d80248cdc7c79be3622e0364da6c943196ea1869b4997b538ae22204
7
+ data.tar.gz: 459e0db583ac0711c40fa15383b6cafb4d9f8972dc2a2aacb89f302212f3769f119c66a7e731d2e4dadcdc7006df163f483308c0795a4e10cec25dfacbb45739
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- codebreaker-Bulatkin (0.1.0)
4
+ codebreaker-Bulatkin (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -19,8 +19,7 @@ module Codebreaker
19
19
  case user_input
20
20
  when I18n.t(:start) then start_game_preparations
21
21
  when I18n.t(:rule) then output(:rules)
22
- when I18n.t(:stats) then statistic(sort_player(load))
23
- when I18n.t(:exit) then exit
22
+ when I18n.t(:stats) then statistic(sort_player)
24
23
  else output(:wrong_command)
25
24
  end
26
25
  end
@@ -49,7 +48,7 @@ module Codebreaker
49
48
  round_menu
50
49
  @guess = user_input
51
50
  hint_menu if guess == I18n.t(:hint)
52
- mark if game.validate_guess(guess)
51
+ mark if game.guess_valid?(guess)
53
52
  won if game.won?(guess)
54
53
  end
55
54
  lost
@@ -89,7 +88,7 @@ module Codebreaker
89
88
 
90
89
  def save_result
91
90
  output(:save)
92
- Storage.save(game.to_yaml(player.name)) if user_input == 'yes'
91
+ game.save(game.to_yaml(player.name)) if user_input == 'yes'
93
92
  end
94
93
 
95
94
  def play_again
@@ -54,12 +54,8 @@ module Codebreaker
54
54
  @attempts -= 1
55
55
  end
56
56
 
57
- def validate_guess(guess)
58
- guess_valid?(guess)
59
- end
60
-
61
57
  def guess(guess)
62
- @result = '+' * exact_match_count(guess) + '-' * number_match_count(guess)
58
+ '+' * exact_match_count(guess) + '-' * number_match_count(guess)
63
59
  end
64
60
 
65
61
  private
@@ -15,9 +15,9 @@ module Codebreaker
15
15
 
16
16
  def validate
17
17
  @errors = []
18
- errors << 'Name cannot be blank' if name.empty?
19
- errors << 'Should be between 3-20 chars' unless size_correct?(name)
20
- errors << 'Should consists of letters' unless class_valid?(name, String)
18
+
19
+ errors << I18n.t('errors.blank') if name.empty?
20
+ errors << I18n.t('errors.size') unless size_correct?(name)
21
21
  end
22
22
  end
23
23
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Codebreaker
4
- VERSION = '0.1.0'
4
+ VERSION = '0.1.1'
5
5
  end
data/lib/locales/en.yml CHANGED
@@ -28,7 +28,9 @@ en:
28
28
  hints_left: 'You have %{hints} hints more'
29
29
  no_hints_left: 'No hints left'
30
30
  game_end: "Want to play one more game?\n"
31
- errors: "Following errors have occured: \n"
31
+ errors:
32
+ blank: 'Name cannot be blank'
33
+ size: 'Should be between 3-20 chars'
32
34
  wrong_command: "You have passed unexpected command. Please choose one from listed commands\n"
33
35
  output_name: 'Write your name, please:'
34
36
  output_difficulty: "\nChoose desired mode:\n-- [hell]\n-- [medium]\n-- [easy]\n"
@@ -1,24 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Codebreaker
4
- PATH = './db'
5
- FILE_NAME = 'data.yml'
6
4
  module Storage
7
- class << self
8
- def save(results)
9
- FileUtils.mkdir_p(PATH) unless Dir.exist?(PATH)
10
- data = load << results
11
- File.open(File.join(Dir.pwd, PATH, FILE_NAME), 'a+') { |file| file.write(data.to_yaml) }
12
- end
13
-
14
- def load
15
- YAML.safe_load(File.join(Dir.pwd, PATH, FILE_NAME))
16
- []
17
- end
18
-
19
- def sort_player
20
- load_database.sort_by { |game| [game[:difficulty], game[:attempts_used], game[:hints_used]] }
21
- end
5
+ PATH = 'db'
6
+ FILE_NAME = 'data.yml'
7
+
8
+ def save(results)
9
+ FileUtils.mkdir_p(PATH) unless Dir.exist?(PATH)
10
+ data = load_database << results
11
+ write_data(data)
12
+ end
13
+
14
+ def load_database
15
+ YAML.safe_load(File.read(file_path))
16
+ end
17
+
18
+ def sort_player
19
+ create_storage unless File.exist?(file_path)
20
+ load_database.sort_by { |game| [game[:difficulty], game[:attempts_used], game[:hints_used]] }
21
+ end
22
+
23
+ private
24
+
25
+ def file_path
26
+ File.join(Dir.pwd, PATH, FILE_NAME)
27
+ end
28
+
29
+ def create_storage
30
+ write_data([])
31
+ end
32
+
33
+ def write_data(data)
34
+ File.open(file_path, 'w') { |file| file.write(data.to_yaml) }
22
35
  end
23
36
  end
24
37
  end
@@ -6,10 +6,6 @@ module Codebreaker
6
6
  value.length.between?(3, 20)
7
7
  end
8
8
 
9
- def class_valid?(value, klass)
10
- value.is_a?(klass)
11
- end
12
-
13
9
  def guess_valid?(value)
14
10
  /^[1-6]{4}$/.match?(value)
15
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreaker-Bulatkin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yevhenii Bulatkin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-11-04 00:00:00.000000000 Z
11
+ date: 2019-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler