Sha256: cf58a09b4353542d70428943ffb6c8d57ffa2e8961cf09816a23ca2f82e9f91e
Contents?: true
Size: 611 Bytes
Versions: 11
Compression:
Stored size: 611 Bytes
Contents
require 'yaml' require_relative '../student/student.rb' require_relative './data_storage_strategy.rb' class YAML_storage_strategy < Data_storage_strategy # read from yaml file def read(file_path) return [] unless File.exist?(file_path) data = YAML.safe_load(File.read(file_path), permitted_classes: [Date, Symbol]) || [] data.map do |student| Student.new_from_hash(student) end end # read to yaml file def write(file_path, students) data = students.map { |student| student.to_h } File.write(file_path, data.to_yaml) end end
Version data entries
11 entries across 11 versions & 1 rubygems