Commit eddd88d7e652de40c874c7096bf7102c1df83bb2
1 parent
54d7aaef
Exists in
master
Improves community_data_export
Signed-off-by: David Carlos <ddavidcarlos1392@gmail.com>
Showing
1 changed file
with
44 additions
and
29 deletions
Show diff stats
lib/community_data_export.rb
1 | 1 | module CommunityDataExport |
2 | 2 | |
3 | + COMMUNITY_FIELDS = %w(public_software acronym finality repository_link) | |
4 | + LICENSE_INFO_FIELDS = %w(id version link) | |
5 | + | |
3 | 6 | def community_attr_to_hash community |
4 | 7 | attrs = {} |
5 | 8 | |
6 | 9 | attrs["members-count"] = community.members.count |
7 | 10 | attrs["members"] = [] |
8 | 11 | |
12 | + attrs = community_members(attrs, community) | |
13 | + | |
14 | + if community.respond_to?("software?") && community.software? | |
15 | + attrs['software_data'] = software_data(community) | |
16 | + attrs = categories(attrs, community) | |
17 | + end | |
18 | + | |
19 | + attrs | |
20 | + end | |
21 | + | |
22 | + def software_data(community) | |
23 | + software_hash = {} | |
24 | + COMMUNITY_FIELDS.each do |m| | |
25 | + software_hash.merge!({m => community.software_info.send(m)}) | |
26 | + end | |
27 | + | |
28 | + software_hash['license_info'] = {} | |
29 | + LICENSE_INFO_FIELDS.each do |m| | |
30 | + software_hash['license_info'].merge!({m => community.software_info.license_info.send(m)}) | |
31 | + end | |
32 | + software_hash | |
33 | + end | |
34 | + | |
35 | + def categories(attrs, community) | |
36 | + attrs['software_data']["categories"] = [] | |
37 | + community.categories.each do |category| | |
38 | + if Category.last.parent.name == "Software" | |
39 | + category_info = { | |
40 | + "id" => category.id, | |
41 | + "name" => category.name, | |
42 | + "slug" => category.slug, | |
43 | + "path" => category.path | |
44 | + } | |
45 | + attrs['software_data']["categories"] << category_info | |
46 | + end | |
47 | + end | |
48 | + attrs | |
49 | + end | |
50 | + | |
51 | + | |
52 | + def community_members(attrs, community) | |
9 | 53 | community.members.each do |member| |
10 | 54 | attrs_members = { |
11 | 55 | "is_admin" => community.admins.include?(member), |
... | ... | @@ -15,35 +59,6 @@ module CommunityDataExport |
15 | 59 | } |
16 | 60 | attrs['members'] << attrs_members |
17 | 61 | end |
18 | - | |
19 | - if community.respond_to?("software?") && community.software? | |
20 | - attrs['software_data'] = { | |
21 | - "public_software" => community.software_info.public_software, | |
22 | - "acronym" => community.software_info.acronym, | |
23 | - "finality" => community.software_info.finality, | |
24 | - "repository_link" => community.software_info.repository_link, | |
25 | - "license_info" => { | |
26 | - "id" => community.software_info.license_info.id, | |
27 | - "version" => community.software_info.license_info.version, | |
28 | - "link" => community.software_info.license_info.link, | |
29 | - }, | |
30 | - "categories" => [] | |
31 | - } | |
32 | - | |
33 | - community.categories.each do |category| | |
34 | - if Category.last.parent.name == "Software" | |
35 | - category_info = { | |
36 | - "id" => category.id, | |
37 | - "name" => category.name, | |
38 | - "slug" => category.slug, | |
39 | - "path" => category.path | |
40 | - } | |
41 | - | |
42 | - attrs['software_data']["categories"] << category_info | |
43 | - end | |
44 | - end | |
45 | - end | |
46 | - | |
47 | 62 | attrs |
48 | 63 | end |
49 | 64 | ... | ... |