diff --git a/app/assets/stylesheets/partials/_results.scss b/app/assets/stylesheets/partials/_results.scss index 8aabfc48..301b02f4 100644 --- a/app/assets/stylesheets/partials/_results.scss +++ b/app/assets/stylesheets/partials/_results.scss @@ -258,6 +258,17 @@ .pub-info { margin-bottom: 4px; + + .format { + border: 2px solid black; + + &.primo { + border-color: purple; + } + &.timdex { + border-color: red; + } + } } ul.contributors { diff --git a/app/models/normalize_primo_record.rb b/app/models/normalize_primo_record.rb index 35999f34..a46c6fe3 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) + 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 @@ -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/vocabularies/format.rb b/app/models/vocabularies/format.rb new file mode 100644 index 00000000..64228e25 --- /dev/null +++ b/app/models/vocabularies/format.rb @@ -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 diff --git a/app/views/search/_result.html.erb b/app/views/search/_result.html.erb index d0f91bd3..40e33507 100644 --- a/app/views/search/_result.html.erb +++ b/app/views/search/_result.html.erb @@ -11,7 +11,7 @@