From bffdd2f07225acf05fbe2a0edac9ebba759121f9 Mon Sep 17 00:00:00 2001 From: Artem Darius Weber Date: Mon, 6 Jan 2025 13:04:11 +0300 Subject: [PATCH] refactor: rename name_initials to surname_initials for consistency --- lab2/README.md | 8 ++++---- lab2/student.rb | 4 ++-- lab2/student_short.rb | 14 +++++++------- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/lab2/README.md b/lab2/README.md index 5c0360d..5595ad1 100644 --- a/lab2/README.md +++ b/lab2/README.md @@ -49,9 +49,9 @@ classDiagram } class StudentShort { - - name_initials : String - + get_name_initials() : String - + StudentShort(id : String, name_initials : String, phone: String, telegram: String, email: String) + - surname_initials : String + + get_surname_initials() : String + + StudentShort(id : String, surname_initials : String, phone: String, telegram: String, email: String) + from_student(student : Student) : StudentShort <> + from_string(id : String, info_string : String) : StudentShort <> + to_s() : String @@ -66,7 +66,7 @@ classDiagram - const NAME_REGEX : String + Student(id : String, git : String, phone: String, telegram: String, email: String, surname : String, name : String, patronymic : String, birth_date : Date) + from_string(student_string : String) : Student <> - + surname_and_initials() : String + + surname_initials() : String + to_s() : String + get_info() : String + surname=(surname : String) diff --git a/lab2/student.rb b/lab2/student.rb index 618895e..c5054a0 100644 --- a/lab2/student.rb +++ b/lab2/student.rb @@ -45,7 +45,7 @@ class Student < Person ) end - def surname_and_initials + def surname_initials "#{@surname} #{name_initial(@name)}.#{patronymic_initial(@patronymic)}." end @@ -56,7 +56,7 @@ class Student < Person end def get_info - "#{surname_and_initials}, Git: #{@git}, Contact: #{get_first_contact}, Birth Date: #{@birth_date}" + "#{surname_initials}, Git: #{@git}, Contact: #{get_first_contact}, Birth Date: #{@birth_date}" end def surname=(surname) diff --git a/lab2/student_short.rb b/lab2/student_short.rb index ea5d884..80bc23a 100644 --- a/lab2/student_short.rb +++ b/lab2/student_short.rb @@ -1,18 +1,18 @@ require_relative 'person' class StudentShort < Person - attr_reader :name_initials + attr_reader :surname_initials - def initialize(id:, name_initials:, phone: nil, telegram: nil, email: nil) + def initialize(id:, surname_initials:, phone: nil, telegram: nil, email: nil) super(id: id, phone: phone, telegram: telegram, email: email) - @name_initials = name_initials + @surname_initials = surname_initials freeze end def self.from_student(student) new( id: student.id, - name_initials: student.surname_and_initials, + surname_initials: student.surname_and_initials, phone: student.phone, telegram: student.telegram, email: student.email @@ -23,14 +23,14 @@ class StudentShort < Person parts = info_string.split(',').map(&:strip) raise ArgumentError, 'Invalid info string format' if parts.size < 2 - name_initials = parts[0] + surname_initials = parts[0] contact_string = parts[1].split(': ', 2).last.strip phone, telegram, email = parse_contact_string(contact_string) new( id: id, - name_initials: name_initials, + surname_initials: surname_initials, phone: phone, telegram: telegram, email: email @@ -39,7 +39,7 @@ class StudentShort < Person def to_s contact_info = get_first_contact() - "#{@name_initials}, Contact: #{contact_info}" + "#{@surname_initials}, Contact: #{contact_info}" end private