Class: Student_short
- Defined in:
- lib/models/student_short/student_short.rb
Instance Attribute Summary collapse
-
#full_name ⇒ Object
readonly
Returns the value of attribute full_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
Attributes inherited from Person
Class Method Summary collapse
-
.new_from_string(id, string) ⇒ Object
constructor from string.
-
.new_from_student_obj(student) ⇒ Object
constructor from Student object.
Instance Method Summary collapse
- #get_any_contact ⇒ Object
-
#initialize(full_name:, git:, contact:, id: nil) ⇒ Student_short
constructor
A new instance of Student_short.
-
#validate? ⇒ Boolean
validate git and contacts.
-
#validate_contacts? ⇒ Boolean
checking for contacts availability.
Methods inherited from Person
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_name ⇒ Object
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 |
#id ⇒ Object
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_contact ⇒ Object
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
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
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 |