-
Notifications
You must be signed in to change notification settings - Fork 0
/
person.rb
54 lines (45 loc) · 996 Bytes
/
person.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require_relative 'nameable'
require_relative 'decorator'
require_relative 'capitalize_decorator'
require_relative 'trimmer_decorator'
require_relative 'classroom'
require_relative 'rental'
# Class representing a person
class Person < Nameable
attr_accessor :name, :age, :rentals, :id
attr_reader :classroom
def initialize(name, age = 'Unknown', parent_permission: true)
super()
@id = rand(1..1000)
@name = name
@age = age
@parent_permission = parent_permission
@rentals = []
end
def classroom=(classroom)
@classroom = classroom
classroom.add_student(self)
end
def add_rentals(book, date)
Rental.new(date, book, self)
end
def correct_name
@name
end
def can_use_services?
@parent_permission || of_age?
end
# Método to_h agregado
def to_h
{
'id' => @id,
'name' => @name,
'age' => @age,
'parent_permission' => @parent_permission
}
end
private
def of_age?
@age >= 18
end
end