Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/assets/stylesheets/partials/_results.scss
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,17 @@

.pub-info {
margin-bottom: 4px;

.format {
border: 2px solid black;

&.primo {
border-color: purple;
}
&.timdex {
border-color: red;
}
}
}

ul.contributors {
Expand Down
11 changes: 1 addition & 10 deletions app/models/normalize_primo_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def year
def format
return unless @record['pnx']['display']['type']

normalize_type(@record['pnx']['display']['type'].join)
Vocabularies::Format.lookup(@record['pnx']['display']['type'].join)
end

# While the links object in the Primo response often contains more than the Alma openurl, that is
Expand Down Expand Up @@ -277,15 +277,6 @@ def encode_author(author)
URI.encode_uri_component(author)
end

def normalize_type(type)
r_types = {
'BKSE' => 'eBook',
'reference_entry' => 'Reference Entry',
'Book_chapter' => 'Book Chapter'
}
r_types[type] || type.capitalize
end

# It's possible we'll encounter records that use a different server,
# so we want to test against our expected server to guard against
# malformed URLs. This assumes all URL strings begin with https://.
Expand Down
27 changes: 27 additions & 0 deletions app/models/vocabularies/format.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module Vocabularies
class Format
# FORMAT_MAPPINGS is an object listing all the machine-friendly format values we have encountered from TIMDEX or
# Primo, and the human-friendly values we want to normalize to. Entries should be alphabetized for easier
# maintenance.
FORMAT_MAPPINGS = {
'BKSE' => 'eBook',
'Book_chapter' => 'Book Chapter',
'Conference_proceeding' => 'Conference Proceeding',
'Magazinearticle' => 'Magazine Article',
'Newsletterarticle' => 'Newsletter Article',
'reference_entry' => 'Reference Entry',
'researchdatabases' => 'Research Database'
}.freeze

# The lookup method attemps to look up a human-friendly value for any of the format values we get back from our
# source systems. The fetch method used allows a default value, which is what happens when a more human-friendly
# value isn't found in the FORMAT_MAPPINGS constant.
#
# @param value [String] A format value to be looked up, if a better version exists.
# @return [String, nil] The cleaned up version, or nil if a nil was submited.
def self.lookup(value)
Rails.logger.debug("Normalizing the format value: _#{value}_")
FORMAT_MAPPINGS.fetch(value, value&.capitalize)
end
end
end
2 changes: 1 addition & 1 deletion app/views/search/_result.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<div class="result-metadata">

<p class="pub-info">
<span><%= result[:content_type]&.each { |type| type['value'] }&.join(' ; ') %></span>
<span class="format timdex"><%= result[:content_type]&.each { |type| type['value'] }&.join(' ; ') %></span>

<% if result[:date_range].present? %>
<span><%= result[:date_range] %></span>
Expand Down
2 changes: 1 addition & 1 deletion app/views/search/_result_primo.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<div class="result-metadata">
<p class="pub-info">
<span><%= result[:format] %></span>
<span class="format primo"><%= result[:format] %></span>
<span><%= result[:year] %></span>
</p>

Expand Down