Skip to content

Commit 9e83341

Browse files
authored
Merge pull request #263 from MITLibraries/use-109-normalized-record-symbols
Use 109 normalized record symbols
2 parents b4195f1 + 6b1a114 commit 9e83341

14 files changed

+206
-199
lines changed

app/helpers/record_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def date_range(range)
1414
end
1515

1616
def publication_date(metadata)
17-
metadata['dates'].select { |date| date['kind'] == 'Publication date' }.first['value']
17+
metadata[:dates].select { |date| date['kind'] == 'Publication date' }.first['value']
1818
end
1919

2020
# Display the machine-format key in human-readable text.

app/helpers/search_helper.rb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ def displayed_fields
44
end
55

66
def trim_highlights(result)
7-
return unless result['highlight']&.any?
7+
return unless result[:highlight]&.any?
88

9-
result['highlight'].reject { |h| displayed_fields.include? h['matchedField'] }
9+
result[:highlight].reject { |h| displayed_fields.include? h['matchedField'] }
1010
end
1111

1212
def format_highlight_label(field_name)
@@ -15,17 +15,17 @@ def format_highlight_label(field_name)
1515
end
1616

1717
def link_to_result(result)
18-
if result['source_link'].present?
19-
link_to(result['title'], result['source_link'])
18+
if result[:source_link].present?
19+
link_to(result[:title], result[:source_link])
2020
else
21-
result['title']
21+
result[:title]
2222
end
2323
end
2424

2525
def view_online(result)
26-
return unless result['source_link'].present?
26+
return unless result[:source_link].present?
2727

28-
link_to 'View online', result['source_link'], class: 'button button-primary'
28+
link_to 'View online', result[:source_link], class: 'button button-primary'
2929
end
3030

3131
def view_record(record_id)

app/models/normalize_primo_record.rb

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ def initialize(record, query)
88
def normalize
99
{
1010
# Core fields
11-
'title' => title,
12-
'creators' => creators,
13-
'source' => source,
14-
'year' => year,
15-
'format' => format,
16-
'links' => links,
17-
'citation' => citation,
18-
'identifier' => record_id,
19-
'summary' => summary,
20-
'publisher' => publisher,
21-
'location' => best_location,
22-
'subjects' => subjects,
11+
title:,
12+
creators:,
13+
source:,
14+
year:,
15+
format:,
16+
links:,
17+
citation:,
18+
identifier:,
19+
summary:,
20+
publisher:,
21+
location:,
22+
subjects:,
2323
# Primo-specific fields
24-
'container' => container_title,
25-
'numbering' => numbering,
26-
'chapter_numbering' => chapter_numbering,
27-
'thumbnail' => thumbnail,
28-
'availability' => best_availability,
29-
'other_availability' => other_availability?
24+
container:,
25+
numbering:,
26+
chapter_numbering:,
27+
thumbnail:,
28+
availability:,
29+
other_availability:
3030
}
3131
end
3232

@@ -115,7 +115,7 @@ def citation
115115
end
116116
end
117117

118-
def container_title
118+
def container
119119
return unless @record['pnx']['addata']
120120

121121
if @record['pnx']['addata']['jtitle'].present?
@@ -125,7 +125,7 @@ def container_title
125125
end
126126
end
127127

128-
def record_id
128+
def identifier
129129
return unless @record['pnx']['control']['recordid']
130130

131131
@record['pnx']['control']['recordid'].join
@@ -224,7 +224,7 @@ def openurl
224224
if openurl_server == record_openurl_server
225225
construct_primo_openurl
226226
else
227-
Rails.logger.warn "Alma openurl server mismatch. Expected #{openurl_server}, but received #{record_openurl_server}. (record ID: #{record_id})"
227+
Rails.logger.warn "Alma openurl server mismatch. Expected #{openurl_server}, but received #{record_openurl_server}. (record ID: #{identifier})"
228228
@record['delivery']['almaOpenurl']
229229
end
230230
end
@@ -265,7 +265,7 @@ def publisher
265265
@record['pnx']['addata']['pub'].first
266266
end
267267

268-
def best_location
268+
def location
269269
return unless @record['delivery']
270270
return unless @record['delivery']['bestlocation']
271271

@@ -279,13 +279,13 @@ def subjects
279279
@record['pnx']['display']['subject']
280280
end
281281

282-
def best_availability
283-
return unless best_location
282+
def availability
283+
return unless location
284284

285285
@record['delivery']['bestlocation']['availabilityStatus']
286286
end
287287

288-
def other_availability?
288+
def other_availability
289289
return unless @record['delivery']['bestlocation']
290290
return unless @record['delivery']['holding']
291291

@@ -302,9 +302,9 @@ def frbrized?
302302
end
303303

304304
def alma_record?
305-
return false unless record_id
305+
return false unless identifier
306306

307-
record_id.start_with?('alma')
307+
identifier.start_with?('alma')
308308
end
309309

310310
def dedup_url

app/models/normalize_timdex_record.rb

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ def initialize(record, query)
88
def normalize
99
{
1010
# Core fields
11-
'title' => title,
12-
'creators' => creators,
13-
'source' => source,
14-
'year' => year,
15-
'format' => format,
16-
'links' => links,
17-
'citation' => citation,
18-
'identifier' => identifier,
19-
'summary' => summary,
20-
'publisher' => publisher,
21-
'location' => location,
22-
'subjects' => subjects,
11+
title:,
12+
creators:,
13+
source:,
14+
year:,
15+
format:,
16+
links:,
17+
citation:,
18+
identifier:,
19+
summary:,
20+
publisher:,
21+
location:,
22+
subjects:,
2323
# TIMDEX-specific fields
24-
'content_type' => content_type,
25-
'dates' => dates,
26-
'contributors' => contributors,
27-
'highlight' => highlight,
28-
'source_link' => source_link
24+
content_type:,
25+
dates:,
26+
contributors:,
27+
highlight:,
28+
source_link:
2929
}
3030
end
3131

app/views/search/_result.html.erb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
</h3>
77

88
<p class="pub-info">
9-
<span><%= result['content_type']&.each { |type| type['value'] }&.join(' ; ') %></span>
9+
<span><%= result[:content_type]&.each { |type| type['value'] }&.join(' ; ') %></span>
1010
<span>
11-
<% result['dates']&.each do |date| %>
11+
<% result[:dates]&.each do |date| %>
1212
<%= date['value'] if date['kind'] == 'Publication date' %>
1313
<% end %>
1414
</span>
1515
</p>
1616

1717
<span class="sr">Contributors: </span>
1818
<ul class="list-inline truncate-list contributors">
19-
<%= render partial: 'shared/contributors', locals: { contributors: result['contributors'] } %>
19+
<%= render partial: 'shared/contributors', locals: { contributors: result[:contributors] } %>
2020
</ul>
2121

2222
<div class="result-highlights">
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
<li class="result">
22
<div class="result-content">
33
<h3 class="record-title">
4-
<span class="sr">Title: </span><%= link_to(result_geo['title'], record_path(result_geo['identifier'])) %>
4+
<span class="sr">Title: </span><%= link_to(result_geo[:title], record_path(result_geo[:identifier])) %>
55
</h3>
66

77
<div class="data-info">
88
<%= render partial: 'shared/geo_data_info', locals: { metadata: result_geo } %>
99
</div>
1010

11-
<% if result_geo['creators'].present? || result_geo['contributors'].present? %>
11+
<% if result_geo[:creators].present? || result_geo[:contributors].present? %>
1212
<span class="sr">Contributors: </span>
1313
<ul class="list-inline truncate-list contributors">
1414
<!-- Use normalized creators if available, otherwise fall back to raw contributors -->
15-
<% contributors = result_geo['creators'].present? ? result_geo['creators'] : result_geo['contributors'] %>
15+
<% contributors = result_geo[:creators].present? ? result_geo[:creators] : result_geo[:contributors] %>
1616
<% if contributors %>
1717
<%= render partial: 'shared/contributors', locals: { contributors: contributors } %>
1818
<% end %>
1919
</ul>
2020
<% end %>
2121

22-
<% if result_geo['summary'].present? %>
22+
<% if result_geo[:summary].present? %>
2323
<p class="result-summary truncate-list">
24-
<span class="sr">Summary: </span><%= result_geo['summary'] %>
24+
<span class="sr">Summary: </span><%= result_geo[:summary] %>
2525
</p>
2626
<% end %>
2727

28-
<% if result_geo['highlight'] %>
28+
<% if result_geo[:highlight] %>
2929
<div class="result-highlights">
30-
<%= render partial: 'search/highlights', locals: { result: { 'highlight' => result_geo['highlight'] } } %>
30+
<%= render partial: 'search/highlights', locals: { result: { highlight: result_geo[:highlight] } } %>
3131
</div>
3232
<% end %>
3333

3434
<div class="result-record">
35-
<%= view_record(result_geo['identifier']) %>
35+
<%= view_record(result_geo[:identifier]) %>
3636
</div>
3737
</div>
3838
</li>

app/views/search/_result_primo.html.erb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
<div class="result-content">
33
<h3 class="record-title">
44
<span class="sr">Title: </span>
5-
<% if result['links']&.find { |link| link['kind'] == 'full record' } %>
6-
<%= link_to(result['title'], result['links'].find { |link| link['kind'] == 'full record' }['url']) %>
5+
<% if result[:links]&.find { |link| link['kind'] == 'full record' } %>
6+
<%= link_to(result[:title], result[:links].find { |link| link['kind'] == 'full record' }['url']) %>
77
<% else %>
8-
<%= result['title'] %>
8+
<%= result[:title] %>
99
<% end %>
1010
</h3>
1111

1212
<p class="pub-info">
13-
<span><%= result['format'] %></span>
14-
<span><%= result['year'] %></span>
13+
<span><%= result[:format] %></span>
14+
<span><%= result[:year] %></span>
1515
</p>
1616

17-
<% if result['creators'].present? %>
17+
<% if result[:creators].present? %>
1818
<span class="sr">Contributors: </span>
1919
<ul class="list-inline truncate-list contributors">
20-
<% result['creators'].each do |creator| %>
20+
<% result[:creators].each do |creator| %>
2121
<li>
2222
<% if creator[:link] %>
2323
<%= link_to creator[:value], creator[:link] %>
@@ -30,8 +30,8 @@
3030
<% end %>
3131

3232
<div class="result-get">
33-
<% if result['links'].present? %>
34-
<% result['links'].each do |link| %>
33+
<% if result[:links].present? %>
34+
<% result[:links].each do |link| %>
3535
<%= link_to link['kind'].titleize, link['url'], class: 'link-button' %>
3636
<% end %>
3737
<% end %>
Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<ul class="list-inline">
2-
<li><%= metadata['contentType']&.each { |type| type['value'] }&.join(' ; ') %></li>
3-
<% if parse_geo_dates(metadata['dates']) %>
2+
<% if metadata[:content_type] %>
3+
<li><%= metadata[:content_type]&.each { |type| type['value'] }&.join(' ; ') %></li>
4+
<% elsif metadata['contentType'] %>
5+
<li><%= metadata['contentType']&.each { |type| type['value'] }&.join(' ; ') %></li>
6+
<% end %>
7+
8+
<% if parse_geo_dates(metadata[:dates]) %>
9+
<li><%= parse_geo_dates(metadata[:dates]) %></li>
10+
<% elsif parse_geo_dates(metadata['dates']) %>
411
<li><%= parse_geo_dates(metadata['dates']) %></li>
512
<% end %>
613
<% if access_type(metadata) == 'unknown: check with owning institution' %>
@@ -11,4 +18,4 @@
1118
<% elsif access_type(metadata) == 'MIT authentication required' %>
1219
<li><span class="access-restricted"><%= access_type(metadata) %></span></li>
1320
<% end %>
14-
</ul>
21+
</ul>

test/controllers/search_controller_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ class SearchControllerTest < ActionDispatch::IntegrationTest
44
def mock_primo_search_success
55
# Mock the Primo search components to avoid external API calls
66
sample_doc = {
7-
'title' => 'Sample Primo Document Title',
8-
'format' => 'Article',
9-
'year' => '2025',
10-
'creators' => [
7+
title: 'Sample Primo Document Title',
8+
format: 'Article',
9+
year: '2025',
10+
creators: [
1111
{ value: 'Foo Barston', link: nil },
1212
{ value: 'Baz Quxley', link: nil }
1313
],
14-
'links' => [{ 'kind' => 'full record', 'url' => 'https://example.com/record' }]
14+
links: [{ 'kind' => 'full record', 'url' => 'https://example.com/record' }]
1515
}
1616

1717
mock_primo = mock('primo_search')

0 commit comments

Comments
 (0)