Sha256: b3dfaa38d63fc080563024db7ad7f908ccd3bb5dec522c627a5509f0e4714e55

Contents?: true

Size: 1.56 KB

Versions: 3

Compression:

Stored size: 1.56 KB

Contents

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

module RubbishCode
    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
Web_rubbish_code-1.0.2 lib/source/student/student_short.rb
Web_rubbish_code-1.0.1 lib/source/student/student_short.rb
Web_rubbish_code-1.0.0 lib/source/student/student_short.rb