Class: Student
- Inherits:
-
StudentBase
- Object
- StudentBase
- Student
- Defined in:
- lib/source/Student.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
Returns the value of attribute email.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#git ⇒ Object
Returns the value of attribute git.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#parental_name ⇒ Object
readonly
Returns the value of attribute parental_name.
-
#phone ⇒ Object
Returns the value of attribute phone.
-
#telegram ⇒ Object
Returns the value of attribute telegram.
Class Method Summary collapse
Instance Method Summary collapse
- #get_git ⇒ Object
- #get_info ⇒ Object
- #get_info_hash ⇒ Object
- #get_short_contact ⇒ Object
- #get_short_fio ⇒ Object
-
#initialize(last_name, first_name, parental_name, options = {}) ⇒ Student
constructor
A new instance of Student.
- #set_contacts(contacts = {}) ⇒ Object
- #to_hash ⇒ Object
- #to_s ⇒ Object
Methods inherited from StudentBase
#first_name=, #last_name=, #parental_name=, #valid_cont?, #validate?, validate_email?, validate_git_tg?, validate_name?, validate_phone?
Constructor Details
#initialize(last_name, first_name, parental_name, options = {}) ⇒ Student
Returns a new instance of Student.
10 11 12 13 14 15 16 17 |
# File 'lib/source/Student.rb', line 10 def initialize(last_name, first_name, parental_name, = {}) super(last_name, first_name, parental_name) self.id = [:id] self.phone = [:phone] self.git = [:git] self.telegram = [:telegram] self.email = [:email] end |
Instance Attribute Details
#email ⇒ Object
Returns the value of attribute email.
8 9 10 |
# File 'lib/source/Student.rb', line 8 def email @email end |
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
8 9 10 |
# File 'lib/source/Student.rb', line 8 def first_name @first_name end |
#git ⇒ Object
Returns the value of attribute git.
8 9 10 |
# File 'lib/source/Student.rb', line 8 def git @git end |
#id ⇒ Object
Returns the value of attribute id.
8 9 10 |
# File 'lib/source/Student.rb', line 8 def id @id end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
8 9 10 |
# File 'lib/source/Student.rb', line 8 def last_name @last_name end |
#parental_name ⇒ Object (readonly)
Returns the value of attribute parental_name.
8 9 10 |
# File 'lib/source/Student.rb', line 8 def parental_name @parental_name end |
#phone ⇒ Object
Returns the value of attribute phone.
8 9 10 |
# File 'lib/source/Student.rb', line 8 def phone @phone end |
#telegram ⇒ Object
Returns the value of attribute telegram.
8 9 10 |
# File 'lib/source/Student.rb', line 8 def telegram @telegram end |
Class Method Details
.from_hash(hash) ⇒ Object
66 67 68 69 70 |
# File 'lib/source/Student.rb', line 66 def self.from_hash(hash) raise ArgumentError,"Missing req fields" unless hash.key?(:last_name) && hash.key?(:first_name) && hash.key?(:parental_name) #переделал этот метод после тестов. Теперь вынимаю обязательные параметры из хэша, не удаляя из него Student.new(hash[:last_name], hash[:first_name], hash[:parental_name], hash) end |
.from_str(string) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/source/Student.rb', line 57 def self.from_str(string) stud = string.split(',') .map{|v| v.split(':')} .map{|v| [v[0].to_sym, v[1]]} .to_h last_name, first_name, parental_name = stud[:fio].split(' ') Student.new(last_name, first_name, parental_name, stud) end |
Instance Method Details
#get_git ⇒ Object
82 83 84 |
# File 'lib/source/Student.rb', line 82 def get_git "git:#{git}" end |
#get_info ⇒ Object
86 87 88 |
# File 'lib/source/Student.rb', line 86 def get_info "#{get_short_fio},#{get_short_contact[:type]}:#{get_short_contact[:val]},#{get_git}" end |
#get_info_hash ⇒ Object
90 91 92 93 94 95 96 |
# File 'lib/source/Student.rb', line 90 def get_info_hash info={} info[:fio] = get_short_fio info[:contact] = get_short_contact info[:git] = git info end |
#get_short_contact ⇒ Object
77 78 79 80 |
# File 'lib/source/Student.rb', line 77 def get_short_contact contact = %i[telegram phone email].find{|cont| send(cont)} {type: contact, val: send(contact)} if contact end |
#get_short_fio ⇒ Object
72 73 74 |
# File 'lib/source/Student.rb', line 72 def get_short_fio "fio:#{last_name} #{first_name[0]}. #{parental_name[0]}." end |
#set_contacts(contacts = {}) ⇒ Object
51 52 53 54 55 |
# File 'lib/source/Student.rb', line 51 def set_contacts(contacts={}) self.phone=contacts[:phone] self.telegram=contacts[:telegram] self.email=contacts[:email] end |
#to_hash ⇒ Object
98 99 100 101 102 103 104 105 |
# File 'lib/source/Student.rb', line 98 def to_hash fields = {} %i[last_name first_name parental_name id phone git telegram email].each do |field| field_val = send(field) fields[field] = field_val unless field_val.nil? end fields end |
#to_s ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/source/Student.rb', line 19 def to_s [ "#{last_name} #{first_name} #{parental_name}", id ? "id: #{id}" : nil, git ? "git: #{git}" : nil, phone ? "phone: #{phone}" : nil, telegram ? "telegram: #{telegram}" : nil, email ? "email: #{email}" : nil ].compact.join(' ') end |