-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunding_csv_to_hash.rb
45 lines (42 loc) · 1.12 KB
/
funding_csv_to_hash.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
require 'csv'
funding_csv = CSV.read("prod_funding_sources.csv")
funding_csv.shift
formatted_funding_data = funding_csv.each_with_object({}) do |row, hash|
# name, ror-identifier, award-number, file-id
name = row[0]
identifier = row[1]
award_number = row[2]
file_id = row[3]
if hash.keys.include?(file_id)
hash[file_id] +=
[{
"funder": {
"name": "#{name}",
"identifier": "#{identifier}",
"scheme": "ror"
},
"award": {
"title": "", # always blank
"number": "#{award_number}",
"identifier": "", # always blank
"scheme": "" # always blank
}
}]
else
hash[file_id] =
[{
"funder": {
"name": "#{name}",
"identifier": "#{identifier}",
"scheme": "ror"
},
"award": {
"title": "", # always blank
"number": "#{award_number}",
"identifier": "", # always blank
"scheme": "" # always blank
}
}]
end
end
File.write("app/models/concerns/galtersufia/generic_file/funding_data.txt", formatted_funding_data)