community_data_export.rb
1.63 KB
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
58
59
60
61
62
63
64
65
module CommunityDataExport
COMMUNITY_FIELDS = %w(public_software acronym finality repository_link)
LICENSE_INFO_FIELDS = %w(id version link)
def community_attr_to_hash community
attrs = {}
attrs["members-count"] = community.members.count
attrs["members"] = []
attrs = community_members(attrs, community)
if community.respond_to?("software?") && community.software?
attrs['software_data'] = software_data(community)
attrs = categories(attrs, community)
end
attrs
end
def software_data(community)
software_hash = {}
COMMUNITY_FIELDS.each do |m|
software_hash.merge!({m => community.software_info.send(m)})
end
software_hash['license_info'] = {}
LICENSE_INFO_FIELDS.each do |m|
software_hash['license_info'].merge!({m => community.software_info.license_info.send(m)})
end
software_hash
end
def categories(attrs, community)
attrs['software_data']["categories"] = []
community.categories.each do |category|
if Category.last.parent.name == "Software"
category_info = {
"id" => category.id,
"name" => category.name,
"slug" => category.slug,
"path" => category.path
}
attrs['software_data']["categories"] << category_info
end
end
attrs
end
def community_members(attrs, community)
community.members.each do |member|
attrs_members = {
"is_admin" => community.admins.include?(member),
"id" => member.id,
"identifier" => member.identifier,
"name" => member.name
}
attrs['members'] << attrs_members
end
attrs
end
end