Commit 998c629818db3dba15b23830b900f6c6536e4fcb
1 parent
fda68f5c
Exists in
master
Add friends, list of communities and softwares at json of person
Signed-off-by: Arthur Del Esposte <arthurmde@gmail.com> Signed-off-by: Gabriela Navarro <navarro1703@gmail.com>
Showing
1 changed file
with
55 additions
and
0 deletions
Show diff stats
@@ -0,0 +1,55 @@ | @@ -0,0 +1,55 @@ | ||
1 | +require_dependency 'person' | ||
2 | + | ||
3 | +class Person | ||
4 | + | ||
5 | + def attr_to_hash | ||
6 | + attrs = super | ||
7 | + | ||
8 | + attrs['friends-count'] = self.friends.count | ||
9 | + attrs['friends'] = [] | ||
10 | + self.friends.each do |friend| | ||
11 | + attrs_friends = { | ||
12 | + "id" => friend.id, | ||
13 | + "identifier" => friend.identifier, | ||
14 | + "name" => friend.name | ||
15 | + } | ||
16 | + attrs['friends'] << attrs_friends | ||
17 | + end | ||
18 | + | ||
19 | + attrs['communities-count'] = self.respond_to?("softwares") ? self.communities.count - self.softwares.count : self.communities.count | ||
20 | + attrs['communities'] = [] | ||
21 | + self.communities.each do |community| | ||
22 | + if community.respond_to?("software?") | ||
23 | + if !community.software? | ||
24 | + attrs_community = { | ||
25 | + "id" => community.id, | ||
26 | + "identifier" => community.identifier, | ||
27 | + "name" => community.name | ||
28 | + } | ||
29 | + attrs['communities'] << attrs_community | ||
30 | + end | ||
31 | + else | ||
32 | + attrs_community = { | ||
33 | + "id" => community.id, | ||
34 | + "identifier" => community.identifier, | ||
35 | + "name" => community.name | ||
36 | + } | ||
37 | + attrs['communities'] << attrs_community | ||
38 | + end | ||
39 | + end | ||
40 | + | ||
41 | + attrs['softwares-count'] = self.respond_to?("softwares") ? self.softwares.count : 0 | ||
42 | + attrs['softwares'] = [] | ||
43 | + if self.respond_to?("softwares") | ||
44 | + self.softwares.each do |software| | ||
45 | + attrs_software = { | ||
46 | + "id" => software.id, | ||
47 | + "identifier" => software.identifier, | ||
48 | + "name" => software.name | ||
49 | + } | ||
50 | + attrs['softwares'] << attrs_software | ||
51 | + end | ||
52 | + end | ||
53 | + attrs | ||
54 | + end | ||
55 | +end |