Sha256: b4b69595753e62e45ce4e0cf0e75d01a537fcba497e81fa32ab8f72bf45cb33d

Contents?: true

Size: 463 Bytes

Versions: 2

Compression:

Stored size: 463 Bytes

Contents

# frozen_string_literal: true

require 'yaml'

module Codebreaker
  module GameWriter
    private

    FILE_NAME = 'scores.yml'.freeze

    def write(player)
      scores = process_file
      scores << player
      scores = scores.max_by(10, &:points)
      File.open(FILE_NAME, 'w') { |f| f.write scores.to_yaml }
    end

    def process_file
      return [] if !File.exist?(FILE_NAME) || File.zero?(FILE_NAME)
      YAML.load_file(FILE_NAME)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ep-codebreaker-0.3.2 lib/ep-codebreaker/game_writer.rb
ep-codebreaker-0.3.1 lib/ep-codebreaker/game_writer.rb