code_brkr_game_training 0.7.5 → 0.8.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: e08993644da18256d3cd3720ec7ccc939ee82074a1effb12659116931c4d2a10
4
- data.tar.gz: e10409ead753bdc0bd7f3cb6c89bdea87ca335c1b481abed9f912b36dd341370
3
+ metadata.gz: fa7c47465b1e2c3dd28ca04daedb8541838f41b5a7a47ddeb810524e6cd18ed0
4
+ data.tar.gz: 3f8a8157e5536ba0fb345b79311ff32749a62e6924c37d36f8af15bf5b63611d
5
5
  SHA512:
6
- metadata.gz: 7ed4ebe5861682f5a3c77cc6e46de4e9d0b5dad2d6eca1390e223cc9208676d9821d19fbb65a2ccaf839c058e04622072b65b07696238ecf66418f804527e854
7
- data.tar.gz: 9375923f2eca595e325eec041bd2852c15da1e7d79a9e4f9b9308110f9ca32332f57c18da3b409befb24c52151a6987287f4c9e9f91c33cc4de42de601735235
6
+ metadata.gz: 942ce924395aed6b92b89f67cdfaa7a678e8e550dc6f1fc2680873aa9f8f9d5ca58d1c4b77b48792c617a03f4297f67248af9cf8c50d289032ea81dd30c4a47e
7
+ data.tar.gz: f7899ade2921c5b9eabff52705dcdbd21135081c6e7b63a538fcf0c6ae0fb6f4160d4325f4eed39ee5023c21da99d7bf5f134de3a7e9741c24a83c7773d561a3
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code_brkr_game_training (0.7.5)
4
+ code_brkr_game_training (0.8.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -7,20 +7,13 @@ module CodeBrkrGameTraining
7
7
  include Validator
8
8
 
9
9
  GAME_DIFFICULTIES = {
10
- easy: { name: 'easy', attempts: 15, hints: 2 },
10
+ hell: { name: 'hell', attempts: 5, hints: 1 },
11
11
  medium: { name: 'medium', attempts: 10, hints: 1 },
12
- hell: { name: 'hell', attempts: 5, hints: 1 }
12
+ easy: { name: 'easy', attempts: 15, hints: 2 }
13
13
  }.freeze
14
14
 
15
15
  attr_reader :init_values, :actual_values
16
16
 
17
- def self.difficulty_levels_order
18
- GAME_DIFFICULTIES
19
- .values
20
- .sort_by { |difficulty| [difficulty[:attempts], difficulty[:hints]] }
21
- .collect { |difficulty| difficulty[:name] }
22
- end
23
-
24
17
  def initialize(difficulty_value)
25
18
  @value_name = difficulty_value
26
19
  validate
@@ -4,14 +4,16 @@
4
4
  module CodeBrkrGameTraining
5
5
  # Module for file operations
6
6
  module FileOperations
7
- def save_to_file(data, path)
8
- yml = YAML.dump(data)
9
- File.open(path, 'a') { |yml_file| yml_file.write(yml) }
7
+ def save_to_file(**args)
8
+ ensuring_directory_availability args[:directory]
9
+
10
+ yml = YAML.dump(args[:data])
11
+ File.open(File.join(args[:directory], args[:file]), 'a') { |yml_file| yml_file.write(yml) }
10
12
  end
11
13
 
12
- def load_from_file(path)
14
+ def load_from_file(directory, file)
13
15
  begin
14
- yml_data = File.open(path, &:read)
16
+ yml_data = File.open(File.join(directory, file), &:read)
15
17
  rescue Errno::ENOENT
16
18
  yml_data = ''
17
19
  end
@@ -20,5 +22,11 @@ module CodeBrkrGameTraining
20
22
  yml_data
21
23
  )
22
24
  end
25
+
26
+ private
27
+
28
+ def ensuring_directory_availability(directory)
29
+ Dir.mkdir(directory) unless Dir.exist?(directory)
30
+ end
23
31
  end
24
32
  end
@@ -4,7 +4,9 @@
4
4
  module CodeBrkrGameTraining
5
5
  # Module for game stats
6
6
  module Statistics
7
- STATISTICS_FILE_PATH = File.dirname(File.expand_path(__FILE__)) + '/../data/game_stats.yml'
7
+ # STATISTICS_FILE_PATH = File.dirname(File.expand_path(__FILE__)) + '/../data/game_stats.yml'
8
+ SAVE_DIRECTORY = 'data'
9
+ SAVE_FILE = 'game_stats.yml'
8
10
 
9
11
  def save_game_results!(user, difficulty)
10
12
  difficulty_init = difficulty.init_values
@@ -15,16 +17,16 @@ module CodeBrkrGameTraining
15
17
  }
16
18
  game_session[:attempts_used] = game_session[:attempts_total] - difficulty_actual[:attempts]
17
19
  game_session[:hints_used] = game_session[:hints_total] - difficulty_actual[:hints]
18
- save_to_file(game_session, STATISTICS_FILE_PATH)
20
+ save_to_file(data: game_session, directory: SAVE_DIRECTORY, file: SAVE_FILE)
19
21
  end
20
22
 
21
23
  def full_statistics
22
- games_array = load_from_file(STATISTICS_FILE_PATH)
24
+ games_array = load_from_file(SAVE_DIRECTORY, SAVE_FILE)
23
25
  return games_array if games_array.empty?
24
26
 
25
- difficulty_order = DifficultyController.difficulty_levels_order
27
+ difficulty_order = DifficultyController::GAME_DIFFICULTIES.keys
26
28
  games_array.sort_by do |game|
27
- [difficulty_order.index(game[:difficulty]), game[:attempts_used], game[:hints_used]]
29
+ [difficulty_order.index(game[:difficulty].to_sym), game[:attempts_used], game[:hints_used]]
28
30
  end
29
31
  end
30
32
  end
@@ -2,5 +2,5 @@
2
2
 
3
3
  # The main module is re-opened here for declaring gem version
4
4
  module CodeBrkrGameTraining
5
- VERSION = '0.7.5'
5
+ VERSION = '0.8.0'
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_brkr_game_training
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.5
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-29 00:00:00.000000000 Z
11
+ date: 2020-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fasterer
@@ -131,7 +131,6 @@ files:
131
131
  - lefthook.yml
132
132
  - lib/code_brkr_game_training.rb
133
133
  - lib/code_brkr_game_training/bootstrap/autoloader.rb
134
- - lib/code_brkr_game_training/data/.keep
135
134
  - lib/code_brkr_game_training/entities/code.rb
136
135
  - lib/code_brkr_game_training/entities/difficulty_controller.rb
137
136
  - lib/code_brkr_game_training/entities/game.rb
File without changes