diff --git a/lib/ext/person.rb b/lib/ext/person.rb new file mode 100644 index 0000000..8a7539e --- /dev/null +++ b/lib/ext/person.rb @@ -0,0 +1,55 @@ +require_dependency 'person' + +class Person + + def attr_to_hash + attrs = super + + attrs['friends-count'] = self.friends.count + attrs['friends'] = [] + self.friends.each do |friend| + attrs_friends = { + "id" => friend.id, + "identifier" => friend.identifier, + "name" => friend.name + } + attrs['friends'] << attrs_friends + end + + attrs['communities-count'] = self.respond_to?("softwares") ? self.communities.count - self.softwares.count : self.communities.count + attrs['communities'] = [] + self.communities.each do |community| + if community.respond_to?("software?") + if !community.software? + attrs_community = { + "id" => community.id, + "identifier" => community.identifier, + "name" => community.name + } + attrs['communities'] << attrs_community + end + else + attrs_community = { + "id" => community.id, + "identifier" => community.identifier, + "name" => community.name + } + attrs['communities'] << attrs_community + end + end + + attrs['softwares-count'] = self.respond_to?("softwares") ? self.softwares.count : 0 + attrs['softwares'] = [] + if self.respond_to?("softwares") + self.softwares.each do |software| + attrs_software = { + "id" => software.id, + "identifier" => software.identifier, + "name" => software.name + } + attrs['softwares'] << attrs_software + end + end + attrs + end +end -- libgit2 0.21.2