Class: Recon::URLLookup
- Inherits:
-
Object
- Object
- Recon::URLLookup
- Defined in:
- lib/ds/recon/url_lookup.rb
Instance Attribute Summary collapse
-
#lookup_set ⇒ Object
readonly
Returns the value of attribute lookup_set.
-
#url_hash ⇒ Object
readonly
Returns the value of attribute url_hash.
Instance Method Summary collapse
- #find_url(holding_inst_as_recorded, shelfmark) ⇒ Object
-
#initialize(lookup_set) ⇒ URLLookup
constructor
The name of the lookup set in
config/recon.yml. - #normalize_key(*strings) ⇒ Object
- #url_key(holder, shelfmark) ⇒ Object
- #urls ⇒ Object
Constructor Details
#initialize(lookup_set) ⇒ URLLookup
The name of the lookup set in config/recon.yml. For example, for
---
recon:
# ...
iiif_manifests: iiif/legacy-iiif-manifests.csv
the lookup_set is 'iiif_manifests'.
18 19 20 21 |
# File 'lib/ds/recon/url_lookup.rb', line 18 def initialize lookup_set @lookup_set = lookup_set @url_hash = {} end |
Instance Attribute Details
#lookup_set ⇒ Object (readonly)
Returns the value of attribute lookup_set.
4 5 6 |
# File 'lib/ds/recon/url_lookup.rb', line 4 def lookup_set @lookup_set end |
#url_hash ⇒ Object (readonly)
Returns the value of attribute url_hash.
5 6 7 |
# File 'lib/ds/recon/url_lookup.rb', line 5 def url_hash @url_hash end |
Instance Method Details
#find_url(holding_inst_as_recorded, shelfmark) ⇒ Object
23 24 25 26 |
# File 'lib/ds/recon/url_lookup.rb', line 23 def find_url holding_inst_as_recorded, shelfmark key = url_key holding_inst_as_recorded, shelfmark urls[key] end |
#normalize_key(*strings) ⇒ Object
48 49 50 |
# File 'lib/ds/recon/url_lookup.rb', line 48 def normalize_key *strings strings.join.downcase.gsub(%r{\s+}, '') end |
#url_key(holder, shelfmark) ⇒ Object
42 43 44 45 46 |
# File 'lib/ds/recon/url_lookup.rb', line 42 def url_key holder, shelfmark qid = DS::Institutions.find_qid holder raise DSError, "No QID found for #{holder}" if qid.blank? normalize_key qid, shelfmark end |
#urls ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/ds/recon/url_lookup.rb', line 30 def urls return url_hash unless url_hash.empty? recon_repo = File.join DS.root, 'data', Settings.recon.git_local_name csv_file = File.join recon_repo, Settings.recon[lookup_set] CSV.readlines(csv_file, headers: true).each { |row| key = url_key row['holding_institution'], row['shelfmark'] url_hash[key] = row['url'] } url_hash end |