lib/alex_codebreaker/session.rb in alex_codebreaker-0.1.12 vs lib/alex_codebreaker/session.rb in alex_codebreaker-0.1.13

- old
+ new

@@ -2,10 +2,11 @@ class Session include AlexCodebreaker::Modules::ArgumentsValidation INITIAL_ATTEMPTS_USED = 0 INITIAL_HINTS_USED = 0 + WINNERS_FILE_NAME = 'winners.yml'.freeze attr_reader :hints_used, :attempts_used, :player_name, :hints_total, :difficulty_name, :attempts_total, :difficulty_level, :time def initialize @@ -36,11 +37,19 @@ return unless @attempts_used < @attempts_total @attempts_used end - def save_statistic + def save_winner_statistic @time = Time.new - File.open(AlexCodebreaker.configuration.storage_path, 'a') { |file| file.write(to_yaml) } + check_folder_existence + path = "#{AlexCodebreaker.configuration.winners_folder_path}#{WINNERS_FILE_NAME}" + File.open(path, 'a') { |file| file.write(to_yaml) } + end + + def check_folder_existence + return if File.directory?(AlexCodebreaker.configuration.winners_folder_path) + + FileUtils.mkdir_p(AlexCodebreaker.configuration.winners_folder_path) end end end