Class: Person::Student

Inherits:
Person
  • Object
show all
Defined in:
lib/entity/person/student.rb

Overview

child class from Person to represent a Student. The Student gains the matriculation number #mat_nr in addition to the attributes from its parent class.

Instance Attribute Summary collapse

Attributes inherited from Person

#id, #name

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name = "def_student", id = PersonIDGenerator.generate_new_id, mat_nr) ⇒ Student

initialization

Parameters:

  • name (String) (defaults to: "def_student")

    the name of the student

  • id (Integer) (defaults to: PersonIDGenerator.generate_new_id)

    the unique id of a person

  • mat_nr (Integer)

    the matriculation number



15
16
17
18
19
# File 'lib/entity/person/student.rb', line 15

def initialize(name="def_student", id=PersonIDGenerator.generate_new_id,
               mat_nr)
  super(name, id)
  @mat_nr = mat_nr
end

Instance Attribute Details

#mat_nrInteger (readonly)

Returns the matriculation number.

Returns:

  • (Integer)

    the matriculation number



9
10
11
# File 'lib/entity/person/student.rb', line 9

def mat_nr
  @mat_nr
end

Class Method Details

.create_from_attribute_list(list) ⇒ Object

singleton method to create a Person::Student from a n array of strings

Parameters:

  • list (Array)

    list of string attributes to create a person

Raises:

  • (ArgumentError)

    if the size of the list does not fit the number of required attributes

See Also:



41
42
43
44
45
# File 'lib/entity/person/student.rb', line 41

def self.create_from_attribute_list(list)
  id = list[1].to_i
  mat_nr = list[2].to_i
  self.new(list[0], id, mat_nr)
end

Instance Method Details

#to_fileString

overwrites the method Person#to_file to create an output string for the output file with all its attributes

Returns:

  • (String)

    a string coding all information of the student for storage



32
33
34
# File 'lib/entity/person/student.rb', line 32

def to_file
  super.concat(";#{@mat_nr}")
end

#to_stringString

overwrites the method Person#to_string to create an output string with all its attributes

Returns:

  • (String)

    output string for this student



24
25
26
# File 'lib/entity/person/student.rb', line 24

def to_string
  super.concat(" and Matriculation: #{@mat_nr}")
end