Skip to content

Commit

Permalink
Full title should be nil if they haven't specified a title
Browse files Browse the repository at this point in the history
  • Loading branch information
jcoyne committed Nov 14, 2018
1 parent 2dd071f commit fdae8c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/stanford-mods/searchworks.rb
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions spec/searchworks_title_spec.rb
Expand Up @@ -27,6 +27,19 @@
end
end

context 'when titleInfo contains a subTitle but no title' do
let(:record) do
m = "<mods #{@ns_decl}><titleInfo><subTitle>An overview from 1942-1950</subTitle></titleInfo></mods>"
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 = "<mods #{@ns_decl}></mods>"
Expand Down

0 comments on commit fdae8c9

Please sign in to comment.