Class: JsonStudentsListFormatStrategy
- Inherits:
-
StudentsListFormatStrategy
- Object
- StudentsListFormatStrategy
- JsonStudentsListFormatStrategy
- Defined in:
- lib/model_gem_source/students_list_format_strategy.rb
Instance Method Summary collapse
Instance Method Details
#read_from(filename) ⇒ Object
34 35 36 37 38 |
# File 'lib/model_gem_source/students_list_format_strategy.rb', line 34 def read_from(filename) file = File.read(filename) json = JSON.parse(file) json.map { |x| Student.from_json(x) } end |
#write_to(filename, students) ⇒ Object
40 41 42 43 44 |
# File 'lib/model_gem_source/students_list_format_strategy.rb', line 40 def write_to(filename, students) File.open(filename, 'w') do |f| f.write(JSON.generate(students.map { |x| x.as_json })) end end |