Module: TaxonWorks::Vendor::Ref2bibtex

Defined in:
lib/vendor/ref2bibtex.rb

Overview

A middle-layer wrapper between Sqed and TaxonWorks

Class Method Summary (collapse)

Class Method Details

+ (Boolean) citation_is_valid_doi?(citation)

Returns Boolean use our global identifier class to determined if value is DOI this isn't super robust, but maybe OK

Returns:

  • (Boolean)

    Boolean use our global identifier class to determined if value is DOI this isn't super robust, but maybe OK



72
73
74
75
76
# File 'lib/vendor/ref2bibtex.rb', line 72

def self.citation_is_valid_doi?(citation)
  doi = Identifier::Global::Doi.new(identifier: citation)
  doi.valid?
  !doi.errors.has_key?(:identifier)
end

+ (String?) get_bibtex_string(citation)

Returns:

  • (String, nil)


47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vendor/ref2bibtex.rb', line 47

def self.get_bibtex_string(citation)
  begin
    if citation_is_valid_doi?(citation)
      a = urize_doi(citation)
      ::Ref2bibtex.get_bibtex(a) 
    else
      ::Ref2bibtex.get(citation) 
    end
  rescue Net::HTTPServerException
    return nil
  end
end

+ (Source::BibTex.new, ...) new_from_citation(citation: nil)

TODO: attempt to extract DOI from full string

Four possible paths: 1) citation. 2) citation which includes a doi. 3) naked doi, e.g., '10.3897/zookeys.20.205'. 4) doi with preamble, e.g., 'dx.doi.org/10.3897/zookeys.20.205' or

'https://doi.org/10.3897/zookeys.20.205'.

Returns:

  • (Source::BibTex.new)

    a new instance

  • (Source::Verbatim.new)

    a new instance

  • (false)


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/vendor/ref2bibtex.rb', line 29

def self.new_from_citation(citation: nil)
  return false if citation.length < 6

  # check string encoding, if not UTF-8, check if compatible with UTF-8,
  # if so convert to UTF-8 and parse with latex, else use type verbatim
  a = get_bibtex_string(citation) 
  b = ::Utilities::Strings.encode_with_utf8(a) if a

  if b
    Source::Bibtex.new_from_bibtex(
      BibTeX.parse(b).convert(:latex).first
    )
  else
    Source::Verbatim.new(verbatim: a ? a : citation)
  end
end

+ (String) urize_doi(doi)

Returns:

  • (String)


61
62
63
64
65
66
67
# File 'lib/vendor/ref2bibtex.rb', line 61

def self.urize_doi(doi)
  if doi =~ /http/
    doi
  else
    'https://doi.org/' + doi
  end
end