22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/paper_summary.rb', line 22
def summary_for_elife(doi)
fluiddb = JSON.parse(open("http://fluiddb.fluidinfo.com/values?query=elifesciences.org/api_v1/article/doi=%22#{doi}%22&tag=*").read)
doi = fluiddb['results']['id'].values.first['fluiddb/about']['value'].match(/doi\.org\/(.*)/)[1]
url = URI.parse('http://dx.doi.org')
res = Net::HTTP.start(url.host, url.port) {|http|
http.get("/#{doi}")
}
url = URI.parse(res['location'])
res = Net::HTTP.start(url.host, url.port) {|http|
http.get(url.path)
}
elife_xml_url = res['location'] + '.source.xml'
xml = Nokogiri::XML(open(elife_xml_url)).css('abstract[abstract-type="executive-summary"] p')
summary = {}
summary[:summary_html] = xml.to_html
summary[:summary_text] = xml.text
summary
end
|