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

Version Path
student_mvp-0.1.10 lib/models/data_storage_strategy/YAML_storage_strategy.rb
student_mvp-0.1.9 lib/models/data_storage_strategy/YAML_storage_strategy.rb
student_mvp-0.1.8 lib/models/data_storage_strategy/YAML_storage_strategy.rb
student_mvp-0.1.7 lib/models/data_storage_strategy/YAML_storage_strategy.rb
student_mvp-0.1.6 lib/models/data_storage_strategy/YAML_storage_strategy.rb
student_mvp-0.1.5 lib/models/data_storage_strategy/YAML_storage_strategy.rb
student_mvp-0.1.4 lib/models/data_storage_strategy/YAML_storage_strategy.rb
student_mvp-0.1.3 lib/models/data_storage_strategy/YAML_storage_strategy.rb
student_mvp-0.1.2 lib/models/data_storage_strategy/YAML_storage_strategy.rb
student_mvp-0.1.1 lib/models/data_storage_strategy/YAML_storage_strategy.rb
student_mvp-0.1.0 lib/models/data_storage_strategy/YAML_storage_strategy.rb