codebreaker_kub 0.1.6 → 0.1.7

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: 3a49f0af67627baefe1e347796218ea5ea54d8155e1187ded572e04c28729c0f
4
- data.tar.gz: f4d02d1790d23a479d48f3f24d2e62a20264d231c42c3d7a6c23a1a2532aabd2
3
+ metadata.gz: 368897134f5e57306064d5dcc9b5ad197a11e77070d3b1923b8c9250160af688
4
+ data.tar.gz: 918822ffa12cd59fa3744487b0b22415d98fc09c2e38d6f4e6fb7dbfd9d9daa7
5
5
  SHA512:
6
- metadata.gz: 10154c1f27c0dcb29b36280731de9b3c261eb69e5aebab8947f519a70012e035126f2f412be3bef4d70f41533b4432f23c88e5b88385d1ec00ac8566e22a6359
7
- data.tar.gz: 7a3f12d5f012885f3a0a89e940f5515f4569f0200e31f8bccf301ffdb241496b6388d1ad1c88ba14be31ea063893a689d1fffc74a22690d69ef8a89e2b21e16c
6
+ metadata.gz: 2caf1d95e69d331e6de3d39f65007d5d3402388f550475cda78a53b8504a1d65f65ed3e63d72380a199163a4d731d4906c46c57de31443bb2cc0b6cb83d2dba6
7
+ data.tar.gz: 58b74baba40482c14d058334ba18cc57b490c468c97e68f7c39dacc0ef52b22dda652637dc37724a291a697970e02e485bd3e966893fbd5fff70c26adc17b030
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- codebreaker_kub (0.1.5)
4
+ codebreaker_kub (0.1.6)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -76,8 +76,8 @@ module Codebreaker
76
76
  attempts: difficulty_option[:attempts],
77
77
  hints: difficulty_option[:hints],
78
78
  code: @code,
79
- attempts_left: @attempts_left,
80
- hints_left: @hints_left,
79
+ used_attempts: difficulty_option[:attempts] - @attempts_left,
80
+ used_hints: difficulty_option[:hints] - @hints_left,
81
81
  win: win?
82
82
  }
83
83
  end
@@ -4,12 +4,9 @@ module Codebreaker
4
4
  EXTENCTION = '.yml'.freeze
5
5
  def self.load(file_name)
6
6
  file_name = PATH + file_name + EXTENCTION.to_s
7
- if File.exist?(file_name)
8
- YAML.load_file(file_name)
9
- else
10
- File.new(file_name, 'w')
11
- []
12
- end
7
+ raise LoadError, 'No such file to load' unless File.exist?(file_name)
8
+
9
+ YAML.load_file(file_name)
13
10
  end
14
11
 
15
12
  def self.save(obj, file_name)
@@ -27,16 +27,23 @@ module Codebreaker
27
27
  puts I18n.t(:rules)
28
28
  end
29
29
 
30
+ def sort_stats
31
+ @stats = @stats.sort_by do |game|
32
+ [game[:attempts], game[:used_attempts],
33
+ game[:used_hints]]
34
+ end
35
+ end
36
+
30
37
  def show_stats
31
- @stats.each do |game|
38
+ sort_stats
39
+ @stats.each_with_index do |game, index|
32
40
  puts "Hey, #{game[:name]}
41
+ Rating: #{index + 1}
33
42
  Attempts: #{game[:attempts]}
34
43
  Hints: #{game[:hints]}
35
- Code: #{game[:code]}
36
44
  Chosen difficulty: #{game[:difficulty]}
37
- Unused attempts: #{game[:attempts_left]}
38
- Unused hints: #{game[:hints_left]}
39
- Win: #{game[:win]}"
45
+ Used attempts: #{game[:used_attempts]}
46
+ Used hints: #{game[:used_hints]}"
40
47
  end
41
48
  end
42
49
 
@@ -1,3 +1,3 @@
1
1
  module Codebreaker
2
- VERSION = '0.1.6'.freeze
2
+ VERSION = '0.1.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreaker_kub
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - katia kub