Class: ShnaiderCode::TxtStudentsListFormatStrategy

Inherits:
StudentsListFormatStrategy show all
Defined in:
lib/source/students_list_format_strategy.rb

Instance Method Summary collapse

Instance Method Details

#read_from(filename) ⇒ Object



16
17
18
19
20
# File 'lib/source/students_list_format_strategy.rb', line 16

def read_from(filename)
    File.read(filename)
    .split("\n")
    .map { |v| Student.from_string(v) }
end

#write_to(filename, students) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/source/students_list_format_strategy.rb', line 22

def write_to(filename, students)
    File.open(filename, 'w') { |file| 
        file.write(
            students.map { |student| 
                student.get_info
            }
            .join("\n")
        )
    }
end