module Gtn::Contributors
Parse the git repo to get some facts
Public Class Methods
Convenience method to allow us to handle nil sites, and load directly from disk ourselves.
# File _plugins/gtn/contributors.rb, line 62 def self._load_file(site, category) if site.nil? Jekyll.logger.warn "[GTN/Contributor] Loading #{category} from disk, this access could be improved" File.open("_data/#{category}.yml", 'r') { |f| YAML.safe_load(f) } else site.data[category] end end
Map a contributor ID to their information and type Params:
site
-
Jekyll::Site
object c
-
String
of contributor ID
Returns: Hash
of contributor information String
type of contributor (e.g. 'contributor', 'organisation', 'funder')
# File _plugins/gtn/contributors.rb, line 79 def self.fetch(site, c) if _load_file(site, 'contributors').key?(c) return ['contributor', site.data['contributors'][c]] elsif _load_file(site, 'organisations').key?(c) return ['organisation', site.data['organisations'][c]] elsif _load_file(site, 'funders').key?(c) return ['funder', site.data['funders'][c]] else Jekyll.logger.warn "Contributor #{c} not found" end ['contributor', { 'name' => c }] end
Map a contributor ID to their information and type Params:
site
-
Jekyll::Site
object c
-
String
of contributor ID
Returns: Hash
of contributor information
# File _plugins/gtn/contributors.rb, line 100 def self.fetch_contributor(site, c) fetch(site, c)[1] end
Obtain the contributor's funding URL Params:
c
-
String
of contributor ID
Returns: Boolean
of whether the contributor is a funder or not
# File _plugins/gtn/contributors.rb, line 154 def self.fetch_funding_url(contributor) return contributor['funding_id'] if !contributor.key?('funding_system') case contributor['funding_system'] when 'cordis' "https://cordis.europa.eu/project/id/#{contributor['funding_id']}" when 'erasmusplus' "https://erasmus-plus.ec.europa.eu/projects/search/details/#{contributor['funding_id']}" when 'ukri' "https://gtr.ukri.org/projects?ref=#{contributor['funding_id']}" else Jekyll.logger.error "Unknown funding system #{contributor['funding_system']}" 'ERROR' end end
Map a contributor ID to their information and type Params:
site
-
Jekyll::Site
object c
-
String
of contributor ID
Returns: String
of contributor name
# File _plugins/gtn/contributors.rb, line 111 def self.fetch_name(site, c) fetch(site, c)[1].fetch('name', c) end
Check if a specific contributor is a funder or not Params:
c
-
String
of contributor ID
Returns: Boolean
of whether the contributor is a funder or not
# File _plugins/gtn/contributors.rb, line 144 def self.funder?(site, c) site.data['funders'].key?(c) end
Returns contributors, regardless of whether they are 'contributor' or 'contributions' style Params:
data
-
Hash
of the YAML frontmatter from a material
Returns: Array
of contributor IDs
# File _plugins/gtn/contributors.rb, line 15 def self.get_contributors(data) if data.key?('contributors') data['contributors'] elsif data.key?('contributions') data['contributions'].keys.map { |k| data['contributions'][k] }.flatten else {} end end
List ALL contributors Params:
site
-
Jekyll::Site
object
Returns: Hash
of contributors, funders, organisations merged together
# File _plugins/gtn/contributors.rb, line 121 def self.list(site) site.data['contributors'] .merge(site.data['funders']) .merge(site.data['organisations']) .reject { |c| c['halloffame'] == 'no' } end
Check if a specific contributor is a person or not Params:
c
-
String
of contributor ID
Returns: Boolean
of whether the contributor is a contributor or not
# File _plugins/gtn/contributors.rb, line 134 def self.person?(site, c) site.data['contributors'].key?(c) end