Module: DS::Institutions

Defined in:
lib/ds/institutions.rb

Overview

Class for access configure institutions. Values from config/institutions.yml

File contents look like:

---
institutions:
  Q814779:
    - Beinecke Rare Book & Manuscript Library
    - beinecke
  Q995265:
    - Bryn Mawr College
    - brynmawr

DS.configure! must be invoked before this class is accessed.

Constant Summary collapse

@@names_to_qids =
nil

Class Method Summary collapse

Class Method Details

.find_qid(inst_alias) ⇒ String

Return the QID for the give institution name/alias.

Parameters:

  • inst_alias (String) —

    a name of the institution

Returns:

  • (String) —

    the institution Wikidata QID



38
39
40
41
42
43
# File 'lib/ds/institutions.rb', line 38

def self.find_qid inst_alias
  # try without changes; and then normalize
  names_to_qids[inst_alias] or
    names_to_qids[inst_alias.to_s.strip] or
    names_to_qids[inst_alias.to_s.strip.downcase]
end

.names_to_qids ⇒ Hash

Return the contents of `config/institutions.yml' as hash with the institution names as keys and the Wikidata QIDs as values.

Returns:

  • (Hash)


26
27
28
29
30
31
# File 'lib/ds/institutions.rb', line 26

def self.names_to_qids
  @@names_to_qids ||= Settings.institutions.inject({}) do |h, qid_names|
    qid = qid_names.first.to_s
    qid_names.last.inject(h) { |j, name| j.merge(name => qid) }
  end
end

.preferred_name(inst_alias) ⇒ String

Return the preferred name of the institution for the given alias.

Parameters:

  • inst_alias (String) —

    a name of the institution

Returns:

  • (String) —

    the first list name of the institution



50
51
52
53
# File 'lib/ds/institutions.rb', line 50

def self.preferred_name inst_alias
  qid = find_qid inst_alias
  Settings.institutions[qid.to_sym].first
end