-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperson.rb
58 lines (53 loc) · 1.46 KB
/
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
55
56
57
class Person
attr_accessor :name, :gender, :generations, :parents
def initialize(name, gender, generations, parents)
@name = name
@gender = gender
@generations = generations
@parents = parents
end
def add_parents(home)
self.parents.map! do |parent|
home.family.find { |member| member.name == parent}
end
end
def find_relatives(relation, home)
relatives = nil
case relation
when 'Son'
relatives = home.find_son(self)
when 'Daughter'
relatives = home.find_daughter(self)
when 'Siblings'
relatives = home.find_siblings(self)
when 'Paternal-Uncle'
relatives = home.find_paternal_uncle(self)
when 'Maternal-Uncle'
relatives = home.find_maternal_uncle(self)
when 'Paternal-Aunt'
relatives = home.find_paternal_aunt(self)
when 'Maternal-Aunt'
relatives = home.find_maternal_aunt(self)
when 'Sister-In-Law'
relatives = home.find_sister_in_law(self)
when 'Brother-In-Law'
relatives = home.find_brother_in_law(self)
else
relatives = []
end
relatives
end
def add_child(home, sorted_inputs)
parents = home.find_parents(self)
if self.gender == 'Female' && !parents.empty? #Add Child to Female having patner
child_generations = self.generations.to_i + 1
child = Person.new(sorted_inputs[1], sorted_inputs[2], child_generations, parents)
unless child.nil?
home.family << child
puts "CHILD_ADDITION_SUCCEEDED"
end
else
puts "CHILD_ADDITION_FAILED"
end
end
end