Module: PaperSummary

Defined in:
lib/paper_summary.rb,
lib/paper_summary/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.summary_for(identifier) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/paper_summary.rb', line 12

def summary_for(identifier)
  if identifier =~ /^arxiv\:(.*)/i
    nil # summary_for_arxiv($1.strip)
  elsif identifier =~ /^doi\:\s*(10\.7554\/.*)/i
    summary_for_elife($1.strip)
  elsif identifier =~ /^doi\:(.*)/i
    nil
  end
end

.summary_for_elife(doi) ⇒ Object



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)

  # Get the DOI url
  doi = fluiddb['results']['id'].values.first['fluiddb/about']['value'].match(/doi\.org\/(.*)/)[1]
  
  # Get the eLife url
  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'

  # Get the eLife paper 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