@@ -38,7 +38,7 @@ def title
3838 end
3939 end
4040
41- def creators
41+ def creators
4242 return [ ] unless @record [ 'pnx' ] [ 'display' ] [ 'creator' ] || @record [ 'pnx' ] [ 'display' ] [ 'contributor' ]
4343
4444 author_list = [ ]
@@ -84,7 +84,7 @@ def format
8484 # the one that is most predictably useful to us. The record_link is constructed.
8585 def links
8686 links = [ ]
87-
87+
8888 # Use dedup URL as the full record link if available, otherwise use record link
8989 if dedup_url . present?
9090 links << { 'url' => dedup_url , 'kind' => 'full record' }
@@ -93,9 +93,7 @@ def links
9393 end
9494
9595 # Add openurl if available
96- if openurl . present?
97- links << { 'url' => openurl , 'kind' => 'openurl' }
98- end
96+ links << { 'url' => openurl , 'kind' => 'openurl' } if openurl . present?
9997
10098 # Return links if we found any
10199 links . any? ? links : [ ]
@@ -167,7 +165,7 @@ def record_link
167165 end
168166
169167 def numbering
170- return unless @record [ 'pnx' ] && @record [ 'pnx' ] [ 'addata' ]
168+ return unless @record [ 'pnx' ] [ 'addata' ]
171169 return unless @record [ 'pnx' ] [ 'addata' ] [ 'volume' ]
172170
173171 if @record [ 'pnx' ] [ 'addata' ] [ 'issue' ] . present?
@@ -178,7 +176,7 @@ def numbering
178176 end
179177
180178 def chapter_numbering
181- return unless @record [ 'pnx' ] && @record [ 'pnx' ] [ 'addata' ]
179+ return unless @record [ 'pnx' ] [ 'addata' ]
182180 return unless @record [ 'pnx' ] [ 'addata' ] [ 'btitle' ]
183181 return unless @record [ 'pnx' ] [ 'addata' ] [ 'date' ] && @record [ 'pnx' ] [ 'addata' ] [ 'pages' ]
184182
@@ -192,7 +190,7 @@ def sanitize_authors(authors)
192190
193191 def author_link ( author )
194192 [ ENV . fetch ( 'MIT_PRIMO_URL' ) ,
195- '/discovery/search?query=creator,exact,' ,
193+ '/discovery/search?query=creator,exact,' ,
196194 encode_author ( author ) ,
197195 '&tab=' , ENV . fetch ( 'PRIMO_TAB' ) ,
198196 '&search_scope=all&vid=' ,
@@ -219,7 +217,7 @@ def openurl
219217 return unless @record [ 'delivery' ] && @record [ 'delivery' ] [ 'almaOpenurl' ]
220218
221219 # Check server match
222- openurl_server = ENV [ 'ALMA_OPENURL' ] [ 8 , 4 ]
220+ openurl_server = ENV . fetch ( 'ALMA_OPENURL' , nil ) [ 8 , 4 ]
223221 record_openurl_server = @record [ 'delivery' ] [ 'almaOpenurl' ] [ 8 , 4 ]
224222 if openurl_server == record_openurl_server
225223 construct_primo_openurl
@@ -236,13 +234,13 @@ def construct_primo_openurl
236234 # Search API to redirect to the Primo UI. This is done for UX purposes,
237235 # as the regular Alma link resolver URLs redirect to a plaintext
238236 # disambiguation page.
239- primo_openurl_base = [ ENV [ 'MIT_PRIMO_URL' ] ,
237+ primo_openurl_base = [ ENV . fetch ( 'MIT_PRIMO_URL' , nil ) ,
240238 '/discovery/openurl?institution=' ,
241- ENV [ 'EXL_INST_ID' ] ,
239+ ENV . fetch ( 'EXL_INST_ID' , nil ) ,
242240 '&vid=' ,
243- ENV [ 'PRIMO_VID' ] ,
241+ ENV . fetch ( 'PRIMO_VID' , nil ) ,
244242 '&' ] . join
245- primo_openurl = @record [ 'delivery' ] [ 'almaOpenurl' ] . gsub ( ENV [ 'ALMA_OPENURL' ] , primo_openurl_base )
243+ primo_openurl = @record [ 'delivery' ] [ 'almaOpenurl' ] . gsub ( ENV . fetch ( 'ALMA_OPENURL' , nil ) , primo_openurl_base )
246244
247245 # The ctx params appear to break Primo openurls, so we need to remove them.
248246 params = Rack ::Utils . parse_nested_query ( primo_openurl )
@@ -256,34 +254,39 @@ def thumbnail
256254 # A record can have multiple ISBNs, so we are assuming here that
257255 # the thumbnail URL can be constructed from the first occurrence
258256 isbn = @record [ 'pnx' ] [ 'addata' ] [ 'isbn' ] . first
259- [ ENV [ 'SYNDETICS_PRIMO_URL' ] , '&isbn=' , isbn , '/sc.jpg' ] . join
257+ [ ENV . fetch ( 'SYNDETICS_PRIMO_URL' , nil ) , '&isbn=' , isbn , '/sc.jpg' ] . join
260258 end
261259
262260 def publisher
263261 return unless @record [ 'pnx' ] [ 'addata' ] && @record [ 'pnx' ] [ 'addata' ] [ 'pub' ]
262+
264263 @record [ 'pnx' ] [ 'addata' ] [ 'pub' ] . first
265264 end
266265
267266 def best_location
268267 return unless @record [ 'delivery' ]
269268 return unless @record [ 'delivery' ] [ 'bestlocation' ]
269+
270270 loc = @record [ 'delivery' ] [ 'bestlocation' ]
271271 [ "#{ loc [ 'mainLocation' ] } #{ loc [ 'subLocation' ] } " , loc [ 'callNumber' ] ]
272272 end
273273
274274 def subjects
275275 return [ ] unless @record [ 'pnx' ] [ 'display' ] [ 'subject' ]
276+
276277 @record [ 'pnx' ] [ 'display' ] [ 'subject' ]
277278 end
278279
279280 def best_availability
280281 return unless best_location
282+
281283 @record [ 'delivery' ] [ 'bestlocation' ] [ 'availabilityStatus' ]
282284 end
283285
284286 def other_availability?
285287 return unless @record [ 'delivery' ] [ 'bestlocation' ]
286288 return unless @record [ 'delivery' ] [ 'holding' ]
289+
287290 @record [ 'delivery' ] [ 'holding' ] . length > 1
288291 end
289292
@@ -292,25 +295,26 @@ def other_availability?
292295 def frbrized?
293296 return unless @record [ 'pnx' ] [ 'facets' ]
294297 return unless @record [ 'pnx' ] [ 'facets' ] [ 'frbrtype' ]
298+
295299 @record [ 'pnx' ] [ 'facets' ] [ 'frbrtype' ] . join == '5'
296300 end
297301
298302 def dedup_url
299303 return unless frbrized?
300304 return unless @record [ 'pnx' ] [ 'facets' ] [ 'frbrgroupid' ] &&
301305 @record [ 'pnx' ] [ 'facets' ] [ 'frbrgroupid' ] . length == 1
302-
306+
303307 frbr_group_id = @record [ 'pnx' ] [ 'facets' ] [ 'frbrgroupid' ] . join
304- base = [ ENV [ 'MIT_PRIMO_URL' ] , '/discovery/search?' ] . join
305-
308+ base = [ ENV . fetch ( 'MIT_PRIMO_URL' , nil ) , '/discovery/search?' ] . join
309+
306310 query = {
307311 query : "any,contains,#{ @query } " ,
308- tab : ENV [ 'PRIMO_TAB' ] ,
309- search_scope : ENV [ 'PRIMO_SCOPE' ] ,
312+ tab : ENV . fetch ( 'PRIMO_TAB' , nil ) ,
313+ search_scope : ENV . fetch ( 'PRIMO_SCOPE' , nil ) ,
310314 sortby : 'date_d' ,
311- vid : ENV [ 'PRIMO_VID' ] ,
315+ vid : ENV . fetch ( 'PRIMO_VID' , nil ) ,
312316 facet : "frbrgroupid,include,#{ frbr_group_id } "
313317 } . to_query
314318 [ base , query ] . join
315319 end
316- end
320+ end
0 commit comments