Open URL to resolve DOI with ruby from command line

那年仲夏 提交于 2019-12-06 14:54:57

it seems you must first require a library such as "open-uri" like in the following example:

david@archbox:~$ irb
irb(main):001:0> require 'open-uri'
=> true
irb(main):002:0> open("http://dx.doi.org/10.1038/nrd842","Accept" =>"text/bibliography; style=bibtex"){|f| f.each {|line| print line}}
@article{Atkins_Gershell_2002, title={From the analysts couch: Selective anticancer drugs}, volume={1}, url={http://dx.doi.org/10.1038/nrd842}, DOI={10.1038/nrd842}, number={7}, journal={Nature Reviews Drug Discovery}, publisher={Nature Publishing Group}, author={Atkins, Joshua H. and Gershell, Leland J.}, year={2002}, month={Jul}, pages={491-492}}=> #<StringIO:0x95cf914 @base_uri=#<URI::HTTP:0x95cfcd4 URL:http://data.crossref.org/10.1038%2Fnrd842>, @meta={"date"=>"Mon, 29 Jul 2013 22:54:09 GMT", "server"=>"Apache/2.2.3 (CentOS)", "x-powered-by"=>"Phusion Passenger (mod_rails/mod_rack) 3.0.7", "vary"=>"Accept", "access-control-allow-origin"=>"*", "x-content-type-options"=>"nosniff", "content-length"=>"351", "status"=>"200", "connection"=>"close", "content-type"=>"text/bibliography;charset=utf-8"}, @status=["200", "OK"]>

Create a file to hold your code, perhaps rtest.rb, inside this file paste the following code:

require 'open-uri'
open("http://dx.doi.org/10.1038/nrd842","Accept" =>"text/bibliography; style=bibtex"){|f| f.each {|line| print line}}

Save the file, then run with:

ruby rtest.rb
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!