lib/stanford-mods/searchworks.rb in stanford-mods-2.6.0 vs lib/stanford-mods/searchworks.rb in stanford-mods-2.6.1

- old
+ new

@@ -151,16 +151,17 @@ return unless first_title_info_node && first_title_info_node.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 preParts.sub!(/\.$/, '') if preParts # remove trailing period @@ -176,10 +177,11 @@ end parts.sub!(/\.$/, '') if parts result = parts ? preParts + ". " + parts : preParts return nil unless result + result += "." unless result =~ /[[:punct:]]$/ result.strip! result = nil if result.empty? result end @@ -189,17 +191,24 @@ # title_display = custom, removeTrailingPunct(245abdefghijklmnopqrstuvwxyz, [\\\\,/;:], ([A-Za-z]{4}|[0-9]{3}|\\)|\\,)) # @return [String] value for title_display (like title_full_display without trailing punctuation) def sw_title_display result = sw_full_title return nil unless result + result.sub(/[\.,;:\/\\]+$/, '').strip 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)) } + excluded_title = sw_short_title || sw_title_display + if excluded_title.present? + title_regex = Regexp.new(Regexp.escape(excluded_title)) + full_titles.reject { |s| s =~ title_regex }.reject(&:blank?) + else + full_titles.reject(&:blank?) + end end # Returns a sortable version of the main title # @return [String] value for title_sort field def sw_sort_title @@ -233,10 +242,11 @@ # resource type should be only Map and not include Software, multimedia. # @return <Array[String]> value in the SearchWorks controlled vocabulary def format_main types = typeOfResource return [] unless types + article_genres = ['article', 'Article', 'book chapter', 'Book chapter', 'Book Chapter', 'issue brief', 'Issue brief', 'Issue Brief', 'project report', 'Project report', 'Project Report', 'student project report', 'Student project report', 'Student Project report', 'Student Project Report', @@ -293,10 +303,11 @@ # @return <Array[String]> values for the genre facet in SearchWorks def sw_genre genres = term_values(:genre) return [] unless genres + val = genres.map(&:to_s) thesis_pub = ['thesis', 'Thesis'] val << 'Thesis/Dissertation' if (genres & thesis_pub).any? conf_pub = ['conference publication', 'Conference publication', 'Conference Publication'] @@ -312,9 +323,10 @@ # @return [String] value with the numeric catkey in it, or nil if none exists def catkey catkey = term_values([:record_info, :recordIdentifier]) return nil unless catkey && !catkey.empty? + catkey.first.tr('a', '') # ensure catkey is numeric only end end # class Record end # Module Mods end # Module Stanford