Skip to content

Commit

Permalink
Don't iterate over nil title values (because nil values could be sent…
Browse files Browse the repository at this point in the history
… in via the SubTitle class.
  • Loading branch information
jkeck committed Dec 3, 2013
1 parent 361936b commit e3f1d97
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions lib/mods_display/fields/title.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,29 @@ class ModsDisplay::Title < ModsDisplay::Field

def fields
return_values = []
@values.each do |value|
if displayForm(value)
return_values << ModsDisplay::Values.new(:label => displayLabel(value) || title_label(value), :values => [displayForm(value)])
else
nonSort = nil
title = nil
subTitle = nil
nonSort = value.nonSort.text.strip unless value.nonSort.text.strip.empty?
title = value.title.text.strip unless value.title.text.strip.empty?
subTitle = value.subTitle.text unless value.subTitle.text.strip.empty?
preSubTitle = [nonSort, title].compact.join(" ")
preSubTitle = nil if preSubTitle.strip.empty?
preParts = [preSubTitle, subTitle].compact.join(" : ")
preParts = nil if preParts.strip.empty?
parts = value.children.select do |child|
["partName", "partNumber"].include?(child.name)
end.map do |child|
child.text
end.compact.join(parts_delimiter(value))
parts = nil if parts.strip.empty?
return_values << ModsDisplay::Values.new(:label => displayLabel(value) || title_label(value), :values => [[preParts, parts].compact.join(". ")])
if @values
@values.each do |value|
if displayForm(value)
return_values << ModsDisplay::Values.new(:label => displayLabel(value) || title_label(value), :values => [displayForm(value)])
else
nonSort = nil
title = nil
subTitle = nil
nonSort = value.nonSort.text.strip unless value.nonSort.text.strip.empty?
title = value.title.text.strip unless value.title.text.strip.empty?
subTitle = value.subTitle.text unless value.subTitle.text.strip.empty?
preSubTitle = [nonSort, title].compact.join(" ")
preSubTitle = nil if preSubTitle.strip.empty?
preParts = [preSubTitle, subTitle].compact.join(" : ")
preParts = nil if preParts.strip.empty?
parts = value.children.select do |child|
["partName", "partNumber"].include?(child.name)
end.map do |child|
child.text
end.compact.join(parts_delimiter(value))
parts = nil if parts.strip.empty?
return_values << ModsDisplay::Values.new(:label => displayLabel(value) || title_label(value), :values => [[preParts, parts].compact.join(". ")])
end
end
end
collapse_fields(return_values)
Expand Down

0 comments on commit e3f1d97

Please sign in to comment.