uc3-dmp-citation 0.0.15 → 0.0.17

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b85070e81998508a3c313105c19a0b9278cf216ef63244c66a170b43768f893f
4
- data.tar.gz: 17cede8c1625c1d5cf410e66da106275f860773b6f7bff05eef34218c0ccfe04
3
+ metadata.gz: f0635b611ac4f1050927777a27b9dcbcdff41a44fb15bd04588b6055a86f6684
4
+ data.tar.gz: d4edaf1b8d51cadfbf746bcf5352502d157ab13aaa6feb038ad8a12e760546a5
5
5
  SHA512:
6
- metadata.gz: 10cef531b7850fe4b3780545da0abf473b7558e606c8b3ac06d6d8f32f82ac9bf32c1f616c4672c2ab206163cabe6b7da4881f9b56e57ca08e45422cc6687666
7
- data.tar.gz: 1ecc54d76b5eb89a1baea752ad7b54d5af01bb0667c4d52ec567a9cb50954f1940568ff269f5b54c0589ace8e7286ff03e298fae1b9cae2f6eec418a2b1c8d6f
6
+ metadata.gz: 07cb08cc43d6291d5a6ac0501c13a1ef8723c4eaee0cd43c8328e4f05c11c83ae57ccbe39044cc0735860233be6babfd59af52a37bc1d05b8406b725946e5c63
7
+ data.tar.gz: 2cd826e807172de65d1b32b50b555bd21692f377ae7adba18d4782b077bee87f454f54c0fb11c170108087f5e387d97dd96d2a0cbcdc33257917aa93a300c8da
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Uc3DmpCitation
4
- VERSION = '0.0.15'
4
+ VERSION = '0.0.17'
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?
@@ -35,15 +36,17 @@ module Uc3DmpCitation
35
36
  logger&.warn(message: "Failure fetching citation for #{uri} - #{e.message}")
36
37
  return nil
37
38
  end
38
- return nil if resp.nil? || resp.to_s.strip.empty? || resp.code
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.15
4
+ version: 0.0.17
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-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: byebug