class Terrier::DoiData
Attributes
citation_info[R]
doi[R]
Public Class Methods
new(doi)
click to toggle source
# File lib/terrier/doi_data.rb, line 5 def initialize(doi) @doi = doi end
Public Instance Methods
data()
click to toggle source
# File lib/terrier/doi_data.rb, line 9 def data @citation_info = doi_citation_info { url: citation_info["URL"], journal: citation_info["container-title"], publisher: citation_info["publisher"], title: citation_info["title"], authors: authors, publication_year: publication_year, issn: citation_info["ISSN"], bibliography: bibliography } end
Private Instance Methods
bibliography()
click to toggle source
# File lib/terrier/doi_data.rb, line 25 def bibliography self.class.get("http://dx.doi.org/#{doi}", headers: bibliography_header) .strip .force_encoding("utf-8") .gsub(/(https?:\/\/[\S]+)/, '<a href="\0">\0</a>') .gsub(/(doi:[^\s|<|>]+)/, '<a href="\0">\0</a>') .gsub('="doi:', '="https://doi.org/') end
bibliography_header()
click to toggle source
# File lib/terrier/doi_data.rb, line 39 def bibliography_header { "Accept" => "text/x-bibliography; style=apa" } end
citation_header()
click to toggle source
# File lib/terrier/doi_data.rb, line 43 def citation_header { "Accept" => "application/vnd.citationstyles.csl+json;q=1.0" } end
doi_citation_info()
click to toggle source
# File lib/terrier/doi_data.rb, line 35 def doi_citation_info self.class.get("http://dx.doi.org/#{doi}", headers: citation_header, format: :json) end
publication_year()
click to toggle source
# File lib/terrier/doi_data.rb, line 53 def publication_year citation_info["issued"]["raw"] || citation_info["issued"]["date-parts"][0][0] end