Class: Codebreaker::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/codebreaker/storage.rb

Constant Summary collapse

PATH =
'lib/codebreaker/src/'

Class Method Summary collapse

Class Method Details

.file_path(filename) ⇒ Object



11
12
13
# File 'lib/codebreaker/storage.rb', line 11

def file_path(filename)
  "#{PATH}#{filename}.yml"
end

.load_file(filename) ⇒ Object



7
8
9
# File 'lib/codebreaker/storage.rb', line 7

def load_file(filename)
  YAML.load_file(file_path(filename)) if File.exist?(file_path(filename))
end

.save_score(data) ⇒ Object



15
16
17
18
19
20
# File 'lib/codebreaker/storage.rb', line 15

def save_score(data)
  current_file_path = file_path(:statistics)
  File.new(current_file_path, 'w+') unless File.exist?(current_file_path)
  record = load_file('statistics') || []
  File.write(current_file_path, (record << data).to_yaml)
end