class GemCodebreaker::SerializerDeserializer

Public Class Methods

new() click to toggle source
# File lib/gem_codebreaker/classes/serializer_deserializer.rb, line 5
def initialize
  @file_name = 'game_statistic.yml'
  @statistic_dir = 'data'
  @storage_path = File.expand_path("./#{@statistic_dir}/#{@file_name}")
end

Public Instance Methods

data_dir_get() click to toggle source
# File lib/gem_codebreaker/classes/serializer_deserializer.rb, line 11
def data_dir_get
  data_directory = File.dirname(@storage_path)
  Dir.mkdir(data_directory) unless File.directory?(data_directory)
end
load_game_statistic() click to toggle source
# File lib/gem_codebreaker/classes/serializer_deserializer.rb, line 16
def load_game_statistic
  File.exist?(@storage_path) ? YAML.load_file(@storage_path) : []
end
save_game_statistic(game_statistic) click to toggle source
# File lib/gem_codebreaker/classes/serializer_deserializer.rb, line 20
def save_game_statistic(game_statistic)
  save_game_stat = game_statistic | load_game_statistic
  File.open(@storage_path, 'w') do |file|
    YAML.dump(save_game_stat, file)
  end
end