Class: FAIRChampionHarvester::OpenAlex

Inherits:
Object
  • Object
show all
Defined in:
lib/openalex.rb

Class Method Summary collapse

Class Method Details

.convertToOpenAlex(guid) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/openalex.rb', line 20

def self.convertToOpenAlex(guid)
  guid = guid.sub(%r{^https?://[\w.]+/}, "")
  guid = guid.sub(/^doi:/, "")
  FAIRChampionHarvester::Utils::GUID_TYPES.each do |pair|
    k, regex = pair
    if k == "doi" and regex.match(guid)
      url = "https://api.openalex.org/works/doi:#{guid}"
      return ["doi", url]
    end
  end
  [nil, nil]
end

.openalex_doi(guid, meta) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/openalex.rb', line 3

def self.openalex_doi(guid, meta)
  guid.downcase!
  type, url = convertToOpenAlex(guid) # returns doi, http://lopenalex...

  meta.guidtype = type if meta.guidtype.nil?
  unless type
    meta.comments << "WARN:  Was not given a DOI.  I am going to fail\n"
    return meta
  end
  meta.comments << "INFO:  Found a DOI.\n"

  FAIRChampionHarvester::URL.resolve_url(guid: url, meta: meta, nolinkheaders: true) # the true is to prevent recursive pursuit of link headers
  meta.comments << "INFO: parsing of OpenAlex #{url} complete.\n"

  meta
end