uc3-dmp-citation 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 33d3c1379d1dcfe500b123f98bc555913c3f72d76cad5df9d5bd8f6f03a39852
4
- data.tar.gz: 39b8ac0b6b989c40f52bda21d14e6db32c7b11b6610f8e8a66c33ec48632749c
3
+ metadata.gz: 7c2817afd07293e08976bd32fad38b356079ef155ae14f4ebd7fba69110de83a
4
+ data.tar.gz: 6b985ed4cdf93d42d5ef1a6304c71c3094077ad4398bab1b853ef62ba07d4d99
5
5
  SHA512:
6
- metadata.gz: 0f9625b4776712fe7090e0e3d98f274e1289a9322f8ca18a736f220038894ee5846f60fff6cca66c9eca2f715df9bc6ea6c9a1baf24d719d0534586ae03a43b1
7
- data.tar.gz: 95f3b54d33d563547a49a4a0fb084112ce4122b5e34cd48aeac60dc82d57de79e8ff8380c5e7c04a81b9063a303cb261c5cb4f0334f3cd0ed69b15f16bcebf42
6
+ metadata.gz: aa6b47581cc57faa4bf79f9e079cf57e24054a58ba324ebff96b19c06d8625b593adbfd60337ed732d162c990ceb7fe581d6953f60d01a897c30c123ee1e7097
7
+ data.tar.gz: bd438167069b0f3ce62fc983c26d6ee9207b71a662b06a12ec0c301d49c5a21de87729094d869eb09f83bc689aa7c87ec0f10e2d420268ce365b0bf510287590
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpCitation
4
- VERSION = '0.0.5'
4
+ VERSION = '0.0.6'
5
5
  end
@@ -10,6 +10,7 @@ require 'uc3-dmp-external-api'
10
10
  module Uc3DmpCitation
11
11
  class CiterError < StandardError; end
12
12
 
13
+ # Clas that fetches Citations for a given DOI
13
14
  class Citer
14
15
  DEFAULT_CITATION_STYLE = 'chicago-author-date'
15
16
  DEFAULT_DOI_URL = 'http://doi.org'
@@ -21,20 +22,22 @@ module Uc3DmpCitation
21
22
  MSG_UNABLE_TO_UPDATE = 'Unable to update the citations on the DMP ID.'
22
23
 
23
24
  class << self
25
+ # rubocop:disable Metrics/AbcSize
24
26
  def fetch_citation(doi:, work_type: DEFAULT_WORK_TYPE, style: DEFAULT_CITATION_STYLE, logger: nil)
25
- uri = _doi_to_uri(doi: doi)
27
+ uri = _doi_to_uri(doi:)
26
28
  return nil if uri.nil? || uri.blank?
27
29
 
28
30
  headers = { Accept: 'application/x-bibtex' }
29
31
  logger.debug(message: "Fetching BibTeX from: #{uri}") if logger.respond_to?(:debug)
30
- resp = Uc3DmpExternalApi::Client.call(url: uri, method: :get, additional_headers: headers, logger: logger)
32
+ resp = Uc3DmpExternalApi::Client.call(url: uri, method: :get, additional_headers: headers, logger:)
31
33
  return nil if resp.nil? || resp.to_s.strip.empty?
32
34
 
33
35
  bibtex = BibTeX.parse(_cleanse_bibtex(text: resp))
34
- work_type = work_type.nil? ? determine_work_type(bibtex: bibtex) : work_type
35
- style = style.nil? ? DEFAULT_CITATION_STYLE : style
36
- _bibtex_to_citation(uri: uri, work_type: work_type, style: style, bibtex: bibtex)
36
+ work_type = work_type.nil? ? determine_work_type(bibtex:) : work_type
37
+ style = DEFAULT_CITATION_STYLE if style.nil?
38
+ _bibtex_to_citation(uri:, work_type:, style:, bibtex:)
37
39
  end
40
+ # rubocop:enable Metrics/AbcSize
38
41
 
39
42
  private
40
43
 
@@ -64,20 +67,21 @@ module Uc3DmpCitation
64
67
  # Remove any encoded HTML (e.g. "Regular text $\\lt$strong$\\gt$Bold text$\\lt$/strong$\\gt$")
65
68
  utf8 = utf8.gsub(%r{\$?\\\$?(less|lt|Lt)\$/?[a-zA-Z]+\$?\\\$?(greater|gt|Gt)\$}, '')
66
69
  # Replace any special dash, semicolon and quote characters with a minus sign or single/double quote
67
- utf8 = utf8.gsub(%r{\$?\\(T|t)ext[a-zA-Z]+dash\$?}, '-').gsub(%r{\{(T|t)ext[a-zA-Z]+dash\}}, '-')
68
- .gsub(%r{\$?\\(M|m)athsemicolon\$?}, ':').gsub(%r{\{(M|m)semicolon\}}, ':')
69
- .gsub(%r{\$?\\(T|t)extquotesingle\$?}, "'").gsub(%r{\{(T|t)extquotesingle\}}, "'")
70
- .gsub(%r{\$?\\(T|t)extquotedouble\$?}, '"').gsub(%r{\{(T|t)extquotedouble\}}, '"')
70
+ utf8 = utf8.gsub(/\$?\\(T|t)ext[a-zA-Z]+dash\$?/, '-').gsub(/\{(T|t)ext[a-zA-Z]+dash\}/, '-')
71
+ .gsub(/\$?\\(M|m)athsemicolon\$?/, ':').gsub(/\{(M|m)semicolon\}/, ':')
72
+ .gsub(/\$?\\(T|t)extquotesingle\$?/, "'").gsub(/\{(T|t)extquotesingle\}/, "'")
73
+ .gsub(/\$?\\(T|t)extquotedouble\$?/, '"').gsub(/\{(T|t)extquotedouble\}/, '"')
71
74
  # Remove any remaining `\v` entries which attempt to construct an accented character
72
- utf8.gsub(%r{\\v}, '')
75
+ utf8.gsub(/\\v/, '')
73
76
  end
74
77
 
75
78
  # Convert the BibTeX item to a citation
76
- def _bibtex_to_citation(uri:, work_type: DEFAULT_WORK_TYPE, bibtex:, style: DEFAULT_CITATION_STYLE)
79
+ # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
80
+ def _bibtex_to_citation(uri:, bibtex:, work_type: DEFAULT_WORK_TYPE, style: DEFAULT_CITATION_STYLE)
77
81
  return nil unless uri.is_a?(String) && uri.strip != ''
78
82
  return nil if bibtex.nil? || bibtex.data.nil? || bibtex.data.first.nil?
79
83
 
80
- cp = CiteProc::Processor.new(style: style, format: 'html')
84
+ cp = CiteProc::Processor.new(style:, format: 'html')
81
85
  cp.import(bibtex.to_citeproc)
82
86
  citation = cp.render(:bibliography, id: bibtex.data.first.id)
83
87
  return nil unless citation.is_a?(Array) && citation.any?
@@ -88,22 +92,21 @@ module Uc3DmpCitation
88
92
 
89
93
  unless work_type.nil? || work_type.strip == ''
90
94
  # This supports the :apa and :chicago-author-date styles
91
- citation = citation.gsub(/\.”\s+/, "\.” [#{work_type.gsub('_', ' ').capitalize}]. ")
92
- .gsub(/<\/i>\.\s+/, "<\/i>\. [#{work_type.gsub('_', ' ').capitalize}]. ")
95
+ citation = citation.gsub(/\.”\s+/, ".” [#{work_type.gsub('_', ' ').capitalize}]. ")
96
+ .gsub(%r{</i>\.\s+}, "</i>. [#{work_type.gsub('_', ' ').capitalize}]. ")
93
97
  end
94
98
 
95
99
  # Convert the URL into a link. Ensure that the trailing period is not a part of
96
100
  # the link!
97
- citation.gsub(URI.regexp) do |url|
101
+ citation.gsub(URI::DEFAULT_PARSER.make_regexp) do |url|
98
102
  if url.start_with?('http')
99
- '<a href="%{url}" target="_blank">%{url}</a>.' % {
100
- url: url.end_with?('.') ? uri : "#{uri}."
101
- }
103
+ format('<a href="%{url}" target="_blank">%{url}</a>.', url: url.end_with?('.') ? uri : "#{uri}.")
102
104
  else
103
105
  url
104
106
  end
105
107
  end
106
108
  end
109
+ # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
107
110
  end
108
111
  end
109
112
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uc3-dmp-citation
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-18 00:00:00.000000000 Z
11
+ date: 2023-10-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug
@@ -81,7 +81,7 @@ licenses:
81
81
  - MIT
82
82
  metadata:
83
83
  rubygems_mfa_required: 'false'
84
- post_install_message:
84
+ post_install_message:
85
85
  rdoc_options: []
86
86
  require_paths:
87
87
  - lib
@@ -89,15 +89,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
89
  requirements:
90
90
  - - ">="
91
91
  - !ruby/object:Gem::Version
92
- version: '2.7'
92
+ version: '3.2'
93
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - ">="
96
96
  - !ruby/object:Gem::Version
97
97
  version: '0'
98
98
  requirements: []
99
- rubygems_version: 3.1.6
100
- signing_key:
99
+ rubygems_version: 3.4.10
100
+ signing_key:
101
101
  specification_version: 4
102
102
  summary: DMPTool gem that provides support for fetching BibTex for a DOI and converting
103
103
  it into a citation