Class: Student_short

Inherits:
Person show all
Defined in:
lib/models/student_short/student_short.rb

Instance Attribute Summary collapse

Attributes inherited from Person

#git

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Person

#validate_git?

Constructor Details

#initialize(full_name:, git:, contact:, id: nil) ⇒ Student_short

Returns a new instance of Student_short.



7
8
9
10
11
12
# File 'lib/models/student_short/student_short.rb', line 7

def initialize(full_name:, git:, contact:, id: nil)
    self.id = id
    self.full_name = full_name
    self.git = git
    self.set_contacts(contact)
end

Instance Attribute Details

#full_nameObject

Returns the value of attribute full_name.



4
5
6
# File 'lib/models/student_short/student_short.rb', line 4

def full_name
  @full_name
end

#idObject

Returns the value of attribute id.



4
5
6
# File 'lib/models/student_short/student_short.rb', line 4

def id
  @id
end

Class Method Details

.new_from_string(id, string) ⇒ Object

constructor from string



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/models/student_short/student_short.rb', line 25

def self.new_from_string(id, string)
    hash = self.parse_string(string)
    contact = ''
    if hash['telegram'] then
        contact = "telegram: #{hash['telegram']}"
    elsif hash['email']
        contact = "email: #{hash['email']}"
    else 
        contact = "phone_number #{hash['phone_number']}"
    end
    
    self.new(
        id: id.to_i,
        full_name: hash['full_name'],
        git: hash['git'],
        contact: contact
    )
end

.new_from_student_obj(student) ⇒ Object

constructor from Student object



15
16
17
18
19
20
21
22
# File 'lib/models/student_short/student_short.rb', line 15

def self.new_from_student_obj(student)
    self.new(
        id: student.id.to_i,
        full_name: student.get_full_name.slice(11..-1),
        git: student.git,
        contact: student.get_any_contact
    )
end

Instance Method Details

#get_any_contactObject



54
55
56
# File 'lib/models/student_short/student_short.rb', line 54

def get_any_contact
    @contact
end

#validate?Boolean

validate git and contacts

Returns:

  • (Boolean)


50
51
52
# File 'lib/models/student_short/student_short.rb', line 50

def validate?
    super && self.validate_contacts?
end

#validate_contacts?Boolean

checking for contacts availability

Returns:

  • (Boolean)


45
46
47
# File 'lib/models/student_short/student_short.rb', line 45

def validate_contacts?
    !(self.get_any_contact.nil? || self.get_any_contact == "")
end