Sha256: 97eb44241c6853a05ef79a80cc8ee873574097a21cedf509551fffafa55b1634

Contents?: true

Size: 1.37 KB

Versions: 9

Compression:

Stored size: 1.37 KB

Contents

require_relative "../attr_limited_regex_accessor.rb"
require_relative "./abstract_student.rb"

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

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
mc_delta-0.4.0 lib/source/student/student_short.rb
mc_delta-0.3.0 lib/source/student/student_short.rb
mc_delta-0.2.0 lib/source/student/student_short.rb
mc_delta-0.1.0 lib/source/student/student_short.rb
model_gem-0.2.0 lib/model_gem_source/student/student_short.rb
model_gem-0.1.9 lib/model_gem_source/student/student_short.rb
model_gem-0.1.8 lib/model_gem_source/student/student_short.rb
model_gem-0.1.7 ./model_gem_source/student/student_short.rb
model_gem-0.1.6 ./model_gem_source/student/student_short.rb