Class: ShnaiderCode::StudentListFormat
- Inherits:
-
Object
- Object
- ShnaiderCode::StudentListFormat
- Defined in:
- lib/source/student_list_format.rb
Instance Attribute Summary collapse
-
#formater ⇒ Object
Returns the value of attribute formater.
Instance Method Summary collapse
- #add_student(student) ⇒ Object
- #count ⇒ Object
- #delete_student(id) ⇒ Object
- #get_student(id) ⇒ Object
- #get_students_slice(k, count) ⇒ Object
-
#initialize(formater) ⇒ StudentListFormat
constructor
A new instance of StudentListFormat.
- #read_from(filename) ⇒ Object
- #replace_student(id, student) ⇒ Object
- #sort ⇒ Object
- #write_to(filename) ⇒ Object
Constructor Details
#initialize(formater) ⇒ StudentListFormat
Returns a new instance of StudentListFormat.
6 7 8 |
# File 'lib/source/student_list_format.rb', line 6 def initialize(formater) self.formater = formater end |
Instance Attribute Details
#formater ⇒ Object
Returns the value of attribute formater.
4 5 6 |
# File 'lib/source/student_list_format.rb', line 4 def formater @formater end |
Instance Method Details
#add_student(student) ⇒ Object
24 25 26 |
# File 'lib/source/student_list_format.rb', line 24 def add_student(student) self.students << student end |
#count ⇒ Object
42 43 44 |
# File 'lib/source/student_list_format.rb', line 42 def count() self.students.count end |
#delete_student(id) ⇒ Object
28 29 30 31 |
# File 'lib/source/student_list_format.rb', line 28 def delete_student(id) index = students.index(students.detect { |x| x.id == id.to_s }) self.students.delete_at(index) end |
#get_student(id) ⇒ Object
18 19 20 21 22 |
# File 'lib/source/student_list_format.rb', line 18 def get_student(id) self.students.detect { |x| x.id == id .to_s } end |
#get_students_slice(k, count) ⇒ Object
37 38 39 40 |
# File 'lib/source/student_list_format.rb', line 37 def get_students_slice(k, count) from = [k * count, self.students.count].min to = [self.students.count, from + count].min end |
#read_from(filename) ⇒ Object
10 11 12 |
# File 'lib/source/student_list_format.rb', line 10 def read_from(filename) self.students = formater.read_from(filename) end |
#replace_student(id, student) ⇒ Object
33 34 35 |
# File 'lib/source/student_list_format.rb', line 33 def replace_student(id, student) self.students.map! { |x| x.id == id.to_s ? student : x } end |
#sort ⇒ Object
46 47 48 |
# File 'lib/source/student_list_format.rb', line 46 def sort() self.students.sort_by(&:fio_info) end |
#write_to(filename) ⇒ Object
14 15 16 |
# File 'lib/source/student_list_format.rb', line 14 def write_to(filename) formater.write_to(filename, self.students) end |