Sha256: 2ecbd0cdbe0610dfb6ae473b1c9158f872f9270a7e33d048a5f9f19d94dd126a

Contents?: true

Size: 1.57 KB

Versions: 3

Compression:

Stored size: 1.57 KB

Contents

require "source/attr_limited_regex_accessor.rb"
require "source/student/abstract_student.rb"

module ShnaiderCode
    class StudentShort < AbstractStudent
        attr_private_limited_regex_accessor :git, '/@\w*/'
        attr_private_limited_regex_accessor :email, '/\w*@\w*.\w{2,3}/'

        public_class_method :new

        def initialize(id:, fio:, git:, email:)
            fio_components = fio.split(" ")

            self.id = id
            self.firstname = fio_components[0]
            self.lastname = fio_components[1]
            self.patronymic = fio_components[2]

            self.git = git
            self.email = email
        end

        def self.from_student(student) 
            StudentShort.new(
                id: student.id, 
                fio: "#{student.firstname} #{student.lastname} #{student.patronymic}",
                git: student.git,
                email: student.email
            )
        end

        def self.from_string(id, info) 
            params = info
            .split(";")
            .map { |x| x.split(":") }
            .map { |x| [x[0].to_sym, x[1]] }
            .to_h

            StudentShort.new(
                id: id, 
                fio: params[:fio],
                git: params[:git],
                email: params[:email]
            )
        end

        def fio_info
            "fio:#{firstname} #{lastname.upcase[0]} #{patronymic.upcase[0]}"
        end

        def contacts_info
            "git:#{git};email:#{email}"
        end

        def get_info
            [fio_info, contacts_info].join(";")
        end
    end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shnaider_code-2.0.4 lib/source/student/student_short.rb
shnaider_code-2.0.3 lib/source/student/student_short.rb
shnaider_code-2.0.2 lib/source/student/student_short.rb