uc3-dmp-citation 0.0.16 → 0.0.18

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: d8f6ce6b1e876be86359025dc20ed5f0cb61ce24414c3976f6cfe6cf1ea64a48
4
- data.tar.gz: 8db13b8bed6167b3c888945d59ec0e23a2a47668001f867082b453f859ad1c60
3
+ metadata.gz: 7e4519a4904f1a6588b536ab26e4949a7a296331b1b2e0b2eae1972250492a43
4
+ data.tar.gz: a02d9ce85e76659525040ed8202b11de7236144663a82c418439407efbc03859
5
5
  SHA512:
6
- metadata.gz: deba715a7e4a87f9499d0a5e37357ddda9992b50f5037efbd344b5fc3dcacd7ab3ca2b8a49fd4ff0c8e5d0f5f82d261b3ecc903d8f8f1aff622e9ad05f818806
7
- data.tar.gz: c9acc90c6ea97c091fc4595bc004e18148075d6c3b3d8193e5f4c942434a76dfe8d728cf26c75940234dc4aa0e0010d9bcf91ccd56a2365d0e3efc6bed7fc90e
6
+ metadata.gz: 6e323d8dcae18788d55ce1add762c1daee7a07bae9c9d373953abf56f95d065829997ea3dceb2ceaba569ff7d89637f18cdd82a74a3625dd9ec43ba976466f49
7
+ data.tar.gz: af07b8644f00825f80fe6ae7fb45d4ab4e279257c98c4f11815c13845568c5d0efd9a66a2accd7b30ee224571cb0400f52d89044d1a57eb8d86e168709b01c43
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpCitation
4
- VERSION = '0.0.16'
4
+ VERSION = '0.0.18'
5
5
  end
@@ -23,6 +23,7 @@ module Uc3DmpCitation
23
23
 
24
24
  class << self
25
25
  # rubocop:disable Metrics/AbcSize
26
+
26
27
  def fetch_citation(doi:, work_type: DEFAULT_WORK_TYPE, style: DEFAULT_CITATION_STYLE, logger: nil)
27
28
  uri = _doi_to_uri(doi:)
28
29
  return nil if uri.nil? || uri.blank?
@@ -38,12 +39,14 @@ module Uc3DmpCitation
38
39
  return nil if resp.nil? || resp.to_s.strip.empty?
39
40
 
40
41
  bibtex_to_citation(uri: uri, bibtex_as_string: resp)
42
+
41
43
  end
42
44
  # rubocop:enable Metrics/AbcSize
43
45
 
44
46
  # Convert the specified BibTex string into a citation
45
47
  def bibtex_to_citation(uri:, bibtex_as_string:)
46
- return nil unless bibtex_as_string.is_a?(String) && uri.is_a?(String)
48
+ is_bibtex = looks_like_bibtex(bibtex_as_string)
49
+ return nil unless bibtex_as_string.is_a?(String) && uri.is_a?(String) && is_bibtex
47
50
 
48
51
  bibtex = BibTeX.parse(_cleanse_bibtex(text: bibtex_as_string))
49
52
  work_type = work_type.nil? ? _determine_work_type(bibtex:) : work_type
@@ -117,6 +120,12 @@ module Uc3DmpCitation
117
120
  end
118
121
  end
119
122
  end
123
+
124
+ def looks_like_bibtex(text)
125
+ # Check if the text contains an @ followed by a known entry type
126
+ bibtex_entry_types = %w[article book booklet inbook incollection inproceedings conference manual mastersthesis phdthesis techreport misc unpublished]
127
+ bibtex_entry_types.any? { |type| text.include?("@#{type}") }
128
+ end
120
129
  # rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
121
130
  end
122
131
  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.16
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Riley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-05 00:00:00.000000000 Z
11
+ date: 2025-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug