Class: StudentShort

Inherits:
StudentBase show all
Defined in:
lib/Student_short.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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(id, str) ⇒ StudentShort

Returns a new instance of StudentShort.

Raises:

  • (ArgumentError)


18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/Student_short.rb', line 18

def initialize(id, str)
	info_short = str.split(',')
					.map{|x| x.split(':')}
					.map{|x| [x[0].to_sym, x[1]]}
					.to_h
	raise ArgumentError, 'Missing fields: fio' if info_short[:fio].nil?
	print(info_short)
	self.id=id
	self.fio = info_short[:fio]
	self.git = info_short[:git]
	info_short.delete_if{|k,v| k==:fio||k==:git}
	self.contact = info_short.values.first
end

Instance Attribute Details

#contactObject

Returns the value of attribute contact.



11
12
13
# File 'lib/Student_short.rb', line 11

def contact
  @contact
end

#fioObject

Returns the value of attribute fio.



11
12
13
# File 'lib/Student_short.rb', line 11

def fio
  @fio
end

#gitObject

Returns the value of attribute git.



11
12
13
# File 'lib/Student_short.rb', line 11

def git
  @git
end

#idObject

Returns the value of attribute id.



11
12
13
# File 'lib/Student_short.rb', line 11

def id
  @id
end

Class Method Details

.from_student_class(student) ⇒ Object



13
14
15
16
# File 'lib/Student_short.rb', line 13

def self.from_student_class(student)
	puts("In studentShort: #{student.to_s}")
	StudentShort.new(student.id, student.get_info)
end

Instance Method Details

#to_sObject



33
34
35
36
37
38
# File 'lib/Student_short.rb', line 33

def to_s

	[
		"#{id}, #{fio}, #{git}, #{contact}"
	].compact.join(' ')
end