diff --git a/app/models/normalize_primo_record.rb b/app/models/normalize_primo_record.rb index 35999f34..ba43cbfe 100644 --- a/app/models/normalize_primo_record.rb +++ b/app/models/normalize_primo_record.rb @@ -92,7 +92,7 @@ def year def format return unless @record['pnx']['display']['type'] - normalize_type(@record['pnx']['display']['type'].join) + @record['pnx']['display']['type'].map { |term| Vocabularies::Format.lookup(term) }&.join(' ; ') end # While the links object in the Primo response often contains more than the Alma openurl, that is @@ -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://. diff --git a/app/models/normalize_timdex_record.rb b/app/models/normalize_timdex_record.rb index 440fe951..9684a11c 100644 --- a/app/models/normalize_timdex_record.rb +++ b/app/models/normalize_timdex_record.rb @@ -102,10 +102,11 @@ def year end end + # This is the same as the content_type field below. def format return '' unless @record['contentType'] - @record['contentType'].map { |type| type['value'] }.join(' ; ') + @record['contentType']&.map { |term| Vocabularies::Format.lookup(term) }&.join(' ; ') end def links @@ -158,8 +159,10 @@ def identifier end # TIMDEX-specific methods + + # This is the same as the format field above. def content_type - @record['contentType'] + @record['contentType']&.map { |term| Vocabularies::Format.lookup(term) }&.join(' ; ') end def dates diff --git a/app/models/vocabularies/format.rb b/app/models/vocabularies/format.rb new file mode 100644 index 00000000..2018cfbb --- /dev/null +++ b/app/models/vocabularies/format.rb @@ -0,0 +1,26 @@ +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) + FORMAT_MAPPINGS.fetch(value.downcase, value&.capitalize) + end + end +end diff --git a/app/views/search/_result.html.erb b/app/views/search/_result.html.erb index d0f91bd3..ab39522e 100644 --- a/app/views/search/_result.html.erb +++ b/app/views/search/_result.html.erb @@ -11,7 +11,7 @@