lib/stanford-mods/searchworks.rb in stanford-mods-0.0.27 vs lib/stanford-mods/searchworks.rb in stanford-mods-1.0.0
- old
+ new
@@ -73,11 +73,11 @@
@mods_ng_xml.plain_name.select {|n| n.type_at != 'personal'}.map { |n| n.display_value_w_date }
end
# @return [Array<String>] values for author_corp_display
def sw_corporate_authors
- val=@mods_ng_xml.plain_name.select {|n| n.type_at == 'corporate'}.map { |n| n.display_value_w_date }
+ val = @mods_ng_xml.plain_name.select {|n| n.type_at == 'corporate'}.map { |n| n.display_value_w_date }
val
end
# @return [Array<String>] values for author_meeting_display
def sw_meeting_authors
@@ -121,39 +121,80 @@
# @return [String] value for title_245a_search field
def sw_short_title
short_titles ? short_titles.first : nil
end
- # @return [String] value for title_245_search, title_display, title_full_display
+ # @return [String] value for title_245_search, title_full_display
def sw_full_title
- toret = full_titles ? full_titles.find { |s| s =~ Regexp.new(Regexp.escape(sw_short_title)) } : nil
- if toret
- toret = toret.gsub(/,$/, '')
+ outer_nodes = @mods_ng_xml.title_info
+ outer_node = outer_nodes ? outer_nodes.first : nil
+ if outer_node
+ nonSort = outer_node.nonSort.text.strip.empty? ? nil : outer_node.nonSort.text.strip
+ title = outer_node.title.text.strip.empty? ? nil: outer_node.title.text.strip
+ preSubTitle = nonSort ? [nonSort, title].compact.join(" ") : title
+ preSubTitle.sub!(/:$/, '') if preSubTitle # remove trailing colon
+
+ subTitle = outer_node.subTitle.text.strip
+ preParts = subTitle.empty? ? preSubTitle : preSubTitle + " : " + subTitle
+ preParts.sub!(/\.$/, '') if preParts # remove trailing period
+
+ partName = outer_node.partName.text.strip unless outer_node.partName.text.strip.empty?
+ partNumber = outer_node.partNumber.text.strip unless outer_node.partNumber.text.strip.empty?
+ partNumber.sub!(/,$/, '') if partNumber # remove trailing comma
+ if partNumber && partName
+ parts = partNumber + ", " + partName
+ elsif partNumber
+ parts = partNumber
+ elsif partName
+ parts = partName
+ end
+ parts.sub!(/\.$/, '') if parts
+
+ result = parts ? preParts + ". " + parts : preParts
+ result += "." if !result.match(/[[:punct:]]$/)
+ result = nil if result.empty?
+ result
+ else
+ nil
end
- toret
end
+ # @return [String] value for title_display (like title_full_display without trailing punctuation)
+ def sw_title_display
+ result = sw_full_title ? sw_full_title : nil
+ result.sub!(/[[:punct:]]$/, '') if result
+ result
+ end
+
# this includes all titles except
# @return [Array<String>] values for title_variant_search
def sw_addl_titles
full_titles.select { |s| s !~ Regexp.new(Regexp.escape(sw_short_title)) }
end
# Returns a sortable version of the main title
# @return [String] value for title_sort field
def sw_sort_title
- val = '' + ( sort_title ? sort_title : '')
- val.gsub(/[[:punct:]]*/, '').strip
+ # get nonSort piece
+ outer_nodes = @mods_ng_xml.title_info
+ outer_node = outer_nodes ? outer_nodes.first : nil
+ if outer_node
+ nonSort = outer_node.nonSort.text.strip.empty? ? nil : outer_node.nonSort.text.strip
+ end
+
+ val = '' + ( sw_full_title ? sw_full_title : '')
+ val.sub!(Regexp.new("^" + nonSort), '') if nonSort
+ val.gsub!(/[[:punct:]]*/, '').strip
+ val.squeeze(" ").strip
end
#remove trailing commas
+ # @deprecated in favor of sw_title_display
def sw_full_title_without_commas
- toret = self.sw_full_title
- if toret
- toret = toret.gsub(/,$/, '')
- end
- toret
+ result = self.sw_full_title
+ result.sub!(/,$/, '') if result
+ result
end
# ---- end TITLE ----
# ---- SUBJECT ----
@@ -499,26 +540,31 @@
val << 'Music - Score'
when 'software, multimedia'
val << 'Computer File'
when 'sound recording-musical'
val << 'Music - Recording'
- when 'sound recording-nonmusical'
+ when 'sound recording-nonmusical', 'sound recording'
val << 'Sound Recording'
when 'still image'
val << 'Image'
when 'text'
val << 'Book' if issuance and issuance.include? 'monographic'
- val << 'Book' if genres and genres.include? 'book chapter'
- val << 'Book' if genres and genres.include? 'issue brief'
- val << 'Book' if genres and genres.include? 'libretto'
- val << 'Book' if genres and genres.include? 'report'
- val << 'Book' if genres and genres.include? 'technical report'
- val << 'Book' if genres and genres.include? 'working paper'
- val << 'Conference Proceedings' if genres and genres.include? 'conference publication'
+ book_genres = ['book chapter', 'Book chapter', 'Book Chapter',
+ 'issue brief', 'Issue brief', 'Issue Brief',
+ 'librettos', 'Librettos',
+ 'project report', 'Project report', 'Project Report',
+ 'technical report', 'Technical report', 'Technical Report',
+ 'working paper', 'Working paper', 'Working Paper']
+ val << 'Book' if genres and !(genres & book_genres).empty?
+ conf_pub = ['conference publication', 'Conference publication', 'Conference Publication']
+ val << 'Conference Proceedings' if genres and !(genres & conf_pub).empty?
val << 'Journal/Periodical' if issuance and issuance.include? 'continuing'
- val << 'Journal/Periodical' if genres and genres.include? 'article'
- val << 'Other' if genres and genres.include? 'student project report'
- val << 'Thesis' if genres and genres.include? 'thesis'
+ article = ['article', 'Article']
+ val << 'Journal/Periodical' if genres and !(genres & article).empty?
+ stu_proj_rpt = ['student project report', 'Student project report', 'Student Project report', 'Student Project Report']
+ val << 'Other' if genres and !(genres & stu_proj_rpt).empty?
+ thesis = ['thesis', 'Thesis']
+ val << 'Thesis' if genres and !(genres & thesis).empty?
when 'three dimensional object'
val << 'Other'
end
end
end