From fdae8c97c2338677af04fcb5666836c98d83dc00 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Wed, 14 Nov 2018 11:24:52 -0800 Subject: [PATCH] Full title should be nil if they haven't specified a title --- lib/stanford-mods/searchworks.rb | 5 +++-- spec/searchworks_title_spec.rb | 13 +++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/stanford-mods/searchworks.rb b/lib/stanford-mods/searchworks.rb index 732794c..a7fad16 100644 --- a/lib/stanford-mods/searchworks.rb +++ b/lib/stanford-mods/searchworks.rb @@ -153,12 +153,13 @@ def title first_title_info_node.title.text.strip.empty? ? nil : first_title_info_node.title.text.strip end + # Searchworks requires that the MODS has a '//titleInfo/title' # @return [String] value for title_245_search, title_full_display def sw_full_title + return nil if !first_title_info_node || !title - return nil unless first_title_info_node preSubTitle = nonSort_title ? [nonSort_title, title].compact.join(" ") : title - preSubTitle.sub!(/:$/, '') if preSubTitle # remove trailing colon + preSubTitle.sub!(/:$/, '') subTitle = first_title_info_node.subTitle.text.strip preParts = subTitle.empty? ? preSubTitle : preSubTitle + " : " + subTitle diff --git a/spec/searchworks_title_spec.rb b/spec/searchworks_title_spec.rb index 0224f72..ee050af 100644 --- a/spec/searchworks_title_spec.rb +++ b/spec/searchworks_title_spec.rb @@ -27,6 +27,19 @@ end end + context 'when titleInfo contains a subTitle but no title' do + let(:record) do + m = "An overview from 1942-1950" + rec = Stanford::Mods::Record.new + rec.from_str m + rec + end + + it 'returns nil' do + expect(record.sw_full_title).to be_nil + end + end + context 'missing title node' do it 'deals with missing titleInfo node' do m = ""