Class: Codebreaker::Stats

Inherits:
Object
  • Object
show all
Defined in:
lib/codebraker_ov/entities/stats.rb

Constant Summary collapse

STORE =
'db/stats.yml'.freeze

Class Method Summary collapse

Class Method Details

.loadObject



21
22
23
# File 'lib/codebraker_ov/entities/stats.rb', line 21

def load
  File.exist?(STORE) ? YAML.load_file(STORE) : []
end

.write(player) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/codebraker_ov/entities/stats.rb', line 7

def write(player)
  data = load
  data.push(player)

  sorted = data.sort

  data.map!.with_index do |record, index|
    record.rating = index + 1
    record
  end

  File.write(STORE, sorted.to_yaml)
end