Class: Uc3DmpCitation::Citer

Inherits:
Object
  • Object
show all
Defined in:
lib/uc3-dmp-citation.rb

Overview

Clas that fetches Citations for a given DOI

Constant Summary collapse

DEFAULT_CITATION_STYLE =
'chicago-author-date'
DEFAULT_DOI_URL =
'http://doi.org'
DEFAULT_WORK_TYPE =
'Dataset'
DOI_REGEX =
%r{[0-9]{2}\.[0-9]{4,}/[a-zA-Z0-9/_.-]+}
MSG_BIBTEX_FAILURE =
'Unable to fetch Bibtex for the specified DOI.'
MSG_UNABLE_TO_UPDATE =
'Unable to update the citations on the DMP ID.'

Class Method Summary collapse

Class Method Details

.bibtex_to_citation(bibtex_as_string:) ⇒ Object

Convert the specified BibTex string into a citation



40
41
42
43
44
45
46
47
# File 'lib/uc3-dmp-citation.rb', line 40

def bibtex_to_citation(bibtex_as_string:)
  return nil unless bibtex_as_string.is_a?(String)

  bibtex = BibTeX.parse(_cleanse_bibtex(text: bibtex_as_string))
  work_type = work_type.nil? ? _determine_work_type(bibtex:) : work_type
  style = DEFAULT_CITATION_STYLE if style.nil?
  _bibtex_to_citation(uri:, work_type:, style:, bibtex:)
end

.fetch_citation(doi:, work_type: DEFAULT_WORK_TYPE, style: DEFAULT_CITATION_STYLE, logger: nil) ⇒ Object

rubocop:disable Metrics/AbcSize



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/uc3-dmp-citation.rb', line 26

def fetch_citation(doi:, work_type: DEFAULT_WORK_TYPE, style: DEFAULT_CITATION_STYLE, logger: nil)
  uri = _doi_to_uri(doi:)
  return nil if uri.nil? || uri.blank?

  headers = { Accept: 'application/x-bibtex' }
  logger.debug(message: "Fetching BibTeX from: #{uri}") if logger.respond_to?(:debug)
  resp = Uc3DmpExternalApi::Client.call(url: uri, method: :get, additional_headers: headers, logger:)
  return nil if resp.nil? || resp.to_s.strip.empty?

  bibtex_to_citation(bibtex_as_string: resp)
end