Class: Uc3DmpCitation::Citer
- Inherits:
-
Object
- Object
- Uc3DmpCitation::Citer
- 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
-
.bibtex_to_citation(uri:, bibtex_as_string:) ⇒ Object
Convert the specified BibTex string into a citation.
-
.fetch_citation(doi:, work_type: DEFAULT_WORK_TYPE, style: DEFAULT_CITATION_STYLE, logger: nil) ⇒ Object
rubocop:disable Metrics/AbcSize.
Class Method Details
.bibtex_to_citation(uri:, bibtex_as_string:) ⇒ Object
Convert the specified BibTex string into a citation
47 48 49 50 51 52 53 54 55 |
# File 'lib/uc3-dmp-citation.rb', line 47 def bibtex_to_citation(uri:, bibtex_as_string:) is_bibtex = looks_like_bibtex(bibtex_as_string) return nil unless bibtex_as_string.is_a?(String) && uri.is_a?(String) && is_bibtex 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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/uc3-dmp-citation.rb', line 27 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}") begin resp = Uc3DmpExternalApi::Client.call(url: uri, method: :get, additional_headers: headers, logger:) rescue Uc3DmpExternalApi::ExternalApiError => e logger&.warn(message: "Failure fetching citation for #{uri} - #{e.message}") return nil end return nil if resp.nil? || resp.to_s.strip.empty? bibtex_to_citation(uri: uri, bibtex_as_string: resp) end |