/
plos_comments.rb
39 lines (32 loc) · 1.09 KB
/
plos_comments.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
class PlosComments < Source
def get_query_url(work)
return nil unless work.doi =~ /^10.1371\/journal/
url_private % { :doi => work.doi }
end
def parse_data(result, work, options={})
return result if result[:error]
events = get_events(result, work)
replies = get_sum(events, :event, 'totalNumReplies')
total = events.length + replies
{ events: events,
events_by_day: get_events_by_day(events, work),
events_by_month: get_events_by_month(events),
events_url: nil,
event_count: total,
event_metrics: get_event_metrics(comments: events.length, total: total) }
end
def get_events(result, work)
Array(result['data']).map do |item|
event_time = get_iso8601_from_time(item['created'])
{ "author" => get_authors([item.fetch('creatorFormattedName', "")]),
"title" => item.fetch('title', nil),
"container-title" => 'PLOS Comments',
"issued" => get_date_parts(event_time),
"URL" => work.doi_as_url,
"type" => 'personal_communication' }
end
end
def config_fields
[:url_private]
end
end