codebreaker2018 0.2.8.3 → 0.3.0.2

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: 8fa4cc3d0ef752950287c8c950a12234d20f9740675004ec05ffe1582b6dbccb
4
- data.tar.gz: 00cba10a77519a2d72e14a74f5d134d23a0dc93605b308ed21c4e09410b03962
3
+ metadata.gz: 799d4f49abd9be97d1c508b3b1ec3f3f3e603b274148e4c2474c476a43e63ea2
4
+ data.tar.gz: 5cf0cf34b755af1a5aa8dd71a19bc04a7b7a90e45f7c983c73eda0a5b0c2b8d8
5
5
  SHA512:
6
- metadata.gz: 1752b231b2cd1887b61b3af73711f2ebc223ea8a23d674e44f70b7a7ff6d9679a943e1f01ee3112b4a4bfb4bea4fa05abc77c8d801b2bacfebfc585b2f4d4c42
7
- data.tar.gz: df6249ffabb476eaa0b6ddf1528762436ae8e8b10aefc1abdae6b03c1040d621cb4f8e10935cb4ebe571d0e5e15feeac1f177e28d8e6beaf0fc71064494d7528
6
+ metadata.gz: 1645d38d18512010ee19adf04217ee0b3b9725636a3e565ee5da0e3c47864007209ec7bda17bc3d6de5e4a00534fb41851b348fc357c294709de70b9fc9ae1e1
7
+ data.tar.gz: 994f43db763377fadebf036ed4fab608064f9c11df670a9251e4debcde193380e97f0d6c168f293472ddc16f26b782e8eba591c8e98aafd419bad07efe35d6bc
@@ -1,10 +1,10 @@
1
1
  require 'colorize'
2
2
  require 'erb'
3
- require 'yaml'
4
3
 
5
4
  module Codebreaker
6
5
  class Console
7
6
  include Message
7
+ include Storage
8
8
 
9
9
  DEMO = Game.new('Demo User', 5, 2, :middle, :en)
10
10
  HINT = '-h'.freeze
@@ -44,10 +44,6 @@ module Codebreaker
44
44
  @scores = load_game_data
45
45
  end
46
46
 
47
- def load_game_data
48
- YAML.load(File.open(storage_path, 'r')) rescue []
49
- end
50
-
51
47
  def submit_answer
52
48
  process(user_interaction)
53
49
  end
@@ -143,17 +139,6 @@ module Codebreaker
143
139
  end
144
140
  end
145
141
 
146
- def prepare_storage_dir
147
- storage_dir = File.dirname(storage_path)
148
- Dir.mkdir(storage_dir) unless File.exists?(storage_dir)
149
- end
150
-
151
- def save_to_yml
152
- File.open(storage_path, 'w') do |file|
153
- file.write(YAML.dump(scores))
154
- end
155
- end
156
-
157
142
  def new_game
158
143
  print message['alerts']['new_game']
159
144
  if input_selector
@@ -179,7 +164,7 @@ module Codebreaker
179
164
 
180
165
  def erase_game_data
181
166
  begin
182
- File.delete(storage_path)
167
+ erase_data_file
183
168
  scores.clear
184
169
  puts message['info']['successfully_erased'].green
185
170
  rescue
@@ -4,8 +4,9 @@ module Codebreaker
4
4
  class Localization
5
5
  attr_accessor :lang
6
6
 
7
- def initialize(app_type, lang = :en)
7
+ def initialize(app_type, external_path = false, lang = :en)
8
8
  @lang = lang
9
+ apply_external_path(external_path)
9
10
  select_application(app_type)
10
11
  candidates_to_load
11
12
  merge_localizations
@@ -18,7 +19,15 @@ module Codebreaker
18
19
 
19
20
  private
20
21
 
22
+ def apply_external_path(external_path)
23
+ if Dir.glob("#{external_path}/*/*.yml").empty? && external_path
24
+ raise ArgumentError, 'Invalid external path.'
25
+ end
26
+ @external_path = external_path ? external_path : false
27
+ end
28
+
21
29
  def localizations_dir
30
+ return @external_path if @external_path
22
31
  File.expand_path('./locale/.', File.dirname(__FILE__))
23
32
  end
24
33
 
@@ -41,7 +50,7 @@ module Codebreaker
41
50
 
42
51
  def merge_localizations
43
52
  localizations
44
- loaded_ymls = @ymls_paths.map { |file| YAML.load(File.open(file, 'r')) }
53
+ loaded_ymls = candidates_to_load.map { |file| YAML.load(File.open(file, 'r')) }
45
54
  loaded_ymls.each { |loaded_yml| @localizations.update(loaded_yml) }
46
55
  end
47
56
  end
@@ -1,5 +1,6 @@
1
1
  module Codebreaker
2
2
  module Message
3
+ private
3
4
  def message
4
5
  @locale.localization
5
6
  end
@@ -0,0 +1,26 @@
1
+ require 'yaml'
2
+
3
+ module Codebreaker
4
+ module Storage
5
+ private
6
+ def load_game_data
7
+ YAML.load(File.open(storage_path, 'r')) rescue []
8
+ end
9
+
10
+ def prepare_storage_dir
11
+ storage_dir = File.dirname(storage_path)
12
+ Dir.mkdir(storage_dir) unless File.exists?(storage_dir)
13
+ end
14
+
15
+ def save_to_yml
16
+ scores_to_save = scores | load_game_data
17
+ File.open(storage_path, 'w') do |file|
18
+ file.write(YAML.dump(scores_to_save))
19
+ end
20
+ end
21
+
22
+ def erase_data_file
23
+ File.delete(storage_path)
24
+ end
25
+ end
26
+ end
@@ -1,3 +1,3 @@
1
1
  module Codebreaker
2
- VERSION = '0.2.8.3'
2
+ VERSION = '0.3.0.2'
3
3
  end
data/lib/codebreaker.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require_relative 'codebreaker/version'
2
2
  require_relative 'codebreaker/localization'
3
3
  require_relative 'codebreaker/message'
4
+ require_relative 'codebreaker/storage'
4
5
  require_relative 'codebreaker/game'
5
6
  require_relative 'codebreaker/score'
6
7
  require_relative 'codebreaker/console'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: codebreaker2018
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8.3
4
+ version: 0.3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Trotsenko
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-06-12 00:00:00.000000000 Z
11
+ date: 2018-06-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -95,6 +95,7 @@ files:
95
95
  - lib/codebreaker/localization.rb
96
96
  - lib/codebreaker/message.rb
97
97
  - lib/codebreaker/score.rb
98
+ - lib/codebreaker/storage.rb
98
99
  - lib/codebreaker/version.rb
99
100
  homepage: https://github.com/bestwebua/homework-04-codebreaker
100
101
  licenses: