Method: Student.from_string
- Defined in:
- lib/model_gem_source/student/student.rb
.from_string(str) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/model_gem_source/student/student.rb', line 46 def self.from_string(str) params = str .split(";") .map { |x| x.split(":") } .map { |x| [x[0].to_sym, x[1]] } .to_h if params[:fio] == nil raise "invalid string representation" end fio_components = params[:fio].split(" ") Student.new( lastname: fio_components[0], firstname: fio_components[1], patronymic: fio_components[2], params: params ) end |