Class: ShnaiderCode::JsonStudentsListFormatStrategy
- Inherits:
-
StudentsListFormatStrategy
- Object
- StudentsListFormatStrategy
- ShnaiderCode::JsonStudentsListFormatStrategy
- Defined in:
- lib/source/students_list_format_strategy.rb
Instance Method Summary collapse
Instance Method Details
#read_from(filename) ⇒ Object
35 36 37 38 39 |
# File 'lib/source/students_list_format_strategy.rb', line 35 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
41 42 43 44 45 |
# File 'lib/source/students_list_format_strategy.rb', line 41 def write_to(filename, students) File.open(filename, 'w') do |f| f.write(JSON.generate(students.map { |x| x.as_json })) end end |