Module: PaperMetadata
- Defined in:
- lib/paper_metadata.rb,
lib/paper_metadata/version.rb
Constant Summary collapse
- VERSION =
"0.0.3"
Class Attribute Summary collapse
-
.doi_username ⇒ Object
Returns the value of attribute doi_username.
Class Method Summary collapse
- .metadata_for(identifier) ⇒ Object
- .metadata_for_arxiv(identifier) ⇒ Object
- .metadata_for_doi(doi) ⇒ Object
Class Attribute Details
.doi_username ⇒ Object
Returns the value of attribute doi_username.
9 10 11 |
# File 'lib/paper_metadata.rb', line 9 def doi_username @doi_username end |
Class Method Details
.metadata_for(identifier) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/paper_metadata.rb', line 16 def (identifier) if identifier =~ /^arxiv\:/i (identifier) elsif identifier =~ /^doi\:/i (identifier) end end |
.metadata_for_arxiv(identifier) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/paper_metadata.rb', line 50 def (identifier) identifier.gsub!(/^arXiv\:/i, '') url = URI.parse("http://export.arxiv.org/api/query?search_query=#{CGI.escape(identifier)}&start=0&max_results=1") res = Net::HTTP.get_response(url) doc = Nokogiri::XML(res.body) doc.remove_namespaces! paper = Hash.new if entry = doc.xpath("//entry").first paper[:title] = entry.xpath('title').text paper[:author] = entry.xpath('author').text.strip paper[:id] = entry.xpath('id').text paper[:updated] = entry.xpath('updated').text paper[:summary] = entry.xpath('summary').text paper[:published] = entry.xpath('published').text end paper end |
.metadata_for_doi(doi) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/paper_metadata.rb', line 24 def (doi) doc = Nokogiri::XML(open("http://www.crossref.org/openurl/?id=#{CGI.escape(doi)}&noredirect=true&pid=#{PaperMetadata.doi_username}&format=unixref")) paper = Hash.new if doc.xpath("//titles/title").first paper[:volume] = doc.xpath("//journal_issue/journal_volume/volume").inner_html.to_s paper[:isssue] = doc.xpath("//journal_issue/issue").inner_html.to_s paper[:first_page] = doc.xpath("//pages/first_page").inner_html.to_s paper[:last_page] = doc.xpath("//pages/last_page").inner_html.to_s paper[:title] = doc.xpath("//titles/title").inner_html.to_s paper[:authors] = doc.xpath("//contributors/person_name"). map{ || .content.strip} paper[:authors] = paper[:authors].map do || .gsub(/\s+/, ' ') end.join(', ') paper[:journal] = doc.xpath("//abbrev_title").inner_html + " " + doc.xpath("//journal_issue/publication_date/year").first.inner_html paper[:resource] = doc.xpath("//journal_article/doi_data/resource").inner_html else paper[:status] = :NODOI end paper end |