Skip to content

Instantly share code, notes, and snippets.

@bmiles
Created July 6, 2013 15:35
Show Gist options
  • Save bmiles/5940255 to your computer and use it in GitHub Desktop.
Save bmiles/5940255 to your computer and use it in GitHub Desktop.
require 'httparty'
require 'json'
require 'nokogiri'
require 'open-uri'
#
# This is a shart script to get demo content to populate an inial set of 'science gists'
# We started by trying to call the elife api directly, but it sucked balls
# then we tried to use content negotiation, but that is also flakey
# finally we will had insert the path the the XML
# pass the full xml to nokogiri
# then extract the xml node '<abstract abstract-type="executive-summary"'
class Digest
attr_accessor :gist, :doi
def initialize(doi, gist="no content")
@doi = doi
@gist = doi2gist()
end
def doi2gist()
strippeddoi = @doi.gsub(/dx.doi.org\//, '')
uri = "http://elife.elifesciences.org/elife-source-xml/#{strippeddoi}"
puts strippeddoi
puts uri
elife_raw_xml = open(uri).read
digest_xml_path = 'abstract[abstract-type="executive-summary"]'
xml = Nokogiri::XML(elife_raw_xml)
digest = xml.css(digest_xml_path)
digesttext = digest.text
return digesttext.gsub(/abstract-2#{strippeddoi}.002eLife digest/, '')
end
end
#test doi1: 'dx.doi.org/10.7554/eLife.00782'
#test doi2: 'dx.doi.org/10.7554/eLife.00800'
ben = GistGetter::Digest.new('dx.doi.org/10.7554/eLife.00782')
puts ben.doi
puts ben.gist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment