From e967d931de04dd2837664cb819ec624232794510 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Wed, 14 Nov 2018 11:35:54 -0800 Subject: [PATCH] Update and pin rubocop to 0.60.0 --- .rubocop.yml | 2 +- .rubocop_todo.yml | 75 +++++++++++++++-------- Gemfile | 2 +- lib/stanford-mods/coordinate.rb | 3 + lib/stanford-mods/date_parsing.rb | 12 ++++ lib/stanford-mods/imprint.rb | 24 +++++--- lib/stanford-mods/name.rb | 2 + lib/stanford-mods/origin_info.rb | 14 +++++ lib/stanford-mods/searchworks.rb | 5 ++ lib/stanford-mods/searchworks_subjects.rb | 2 + spec/date_parsing_spec.rb | 2 + spec/imprint_spec.rb | 1 + spec/name_spec.rb | 3 + spec/origin_info_spec.rb | 3 + spec/physical_location_spec.rb | 6 ++ spec/searchworks_pub_dates_spec.rb | 1 + spec/searchworks_spec.rb | 1 + spec/searchworks_subject_raw_spec.rb | 6 ++ spec/searchworks_subject_spec.rb | 2 + spec/searchworks_title_spec.rb | 11 ++++ 20 files changed, 142 insertions(+), 35 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index d4fe079..20e62f3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,7 +3,7 @@ inherit_from: .rubocop_todo.yml require: rubocop-rspec Metrics/LineLength: - Max: 120 + Max: 200 # shut hound up re: quote styles Style/StringLiterals: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 35cf005..9032bfa 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2018-08-08 21:42:13 -0700 using RuboCop version 0.57.1. +# on 2018-11-14 11:35:35 -0800 using RuboCop version 0.60.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -8,7 +8,7 @@ # Offense count: 2 # Cop supports --auto-correct. -# Configuration parameters: Include, TreatCommentsAsGroupSeparators. +# Configuration parameters: TreatCommentsAsGroupSeparators, Include. # Include: **/*.gemfile, **/Gemfile, **/gems.rb Bundler/OrderedGems: Exclude: @@ -22,7 +22,7 @@ Layout/AccessModifierIndentation: Exclude: - 'lib/stanford-mods/origin_info.rb' -# Offense count: 27 +# Offense count: 22 # Cop supports --auto-correct. Layout/AlignArray: Exclude: @@ -47,7 +47,7 @@ Layout/BlockEndNewline: Exclude: - 'spec/name_spec.rb' -# Offense count: 20 +# Offense count: 10 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, IndentOneStep, IndentationWidth. # SupportedStyles: case, end @@ -134,20 +134,20 @@ Layout/SpaceInsideBlockBraces: Exclude: - 'lib/stanford-mods/searchworks.rb' -# Offense count: 11 +# Offense count: 6 # Cop supports --auto-correct. # Configuration parameters: AllowInHeredoc. Layout/TrailingWhitespace: Exclude: - - 'lib/stanford-mods/searchworks.rb' - 'spec/searchworks_spec.rb' -# Offense count: 33 +# Offense count: 32 Metrics/AbcSize: - Max: 56 + Max: 58 -# Offense count: 102 +# Offense count: 97 # Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine Metrics/BlockLength: Max: 795 @@ -156,24 +156,31 @@ Metrics/BlockLength: Metrics/ClassLength: Max: 377 -# Offense count: 20 +# Offense count: 18 Metrics/CyclomaticComplexity: - Max: 26 + Max: 32 -# Offense count: 118 +# Offense count: 116 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: Max: 199 -# Offense count: 32 -# Configuration parameters: CountComments. +# Offense count: 31 +# Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: Max: 52 -# Offense count: 16 +# Offense count: 14 Metrics/PerceivedComplexity: - Max: 20 + Max: 25 + +# Offense count: 1 +# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS +Naming/FileName: + Exclude: + - 'lib/stanford-mods.rb' # Offense count: 24 # Configuration parameters: Blacklist. @@ -207,7 +214,7 @@ Naming/PredicateName: # Offense count: 2 # Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. -# AllowedNames: io, id, to, by, on, in, at +# AllowedNames: io, id, to, by, on, in, at, ip, db Naming/UncommunicativeMethodParamName: Exclude: - 'lib/stanford-mods/imprint.rb' @@ -245,7 +252,7 @@ RSpec/BeforeAfterAll: - 'spec/searchworks_subject_spec.rb' - 'spec/searchworks_title_spec.rb' -# Offense count: 142 +# Offense count: 134 # Configuration parameters: Prefixes. # Prefixes: when, with, without RSpec/ContextWording: @@ -283,6 +290,7 @@ RSpec/DescribeClass: - 'spec/sw_publication_spec.rb' # Offense count: 14 +# Cop supports --auto-correct. RSpec/EmptyLineAfterFinalLet: Exclude: - 'spec/name_spec.rb' @@ -290,7 +298,7 @@ RSpec/EmptyLineAfterFinalLet: - 'spec/physical_location_spec.rb' - 'spec/sw_publication_spec.rb' -# Offense count: 147 +# Offense count: 133 # Configuration parameters: Max. RSpec/ExampleLength: Exclude: @@ -305,7 +313,8 @@ RSpec/ExampleLength: - 'spec/searchworks_subject_spec.rb' - 'spec/searchworks_title_spec.rb' -# Offense count: 114 +# Offense count: 111 +# Cop supports --auto-correct. # Configuration parameters: CustomTransform, IgnoredWords. RSpec/ExampleWording: Exclude: @@ -324,12 +333,13 @@ RSpec/FilePath: - 'spec/lib/stanford-mods/coordinate_spec.rb' # Offense count: 2 +# Cop supports --auto-correct. # Configuration parameters: . # SupportedStyles: implicit, each, example RSpec/HookArgument: EnforcedStyle: each -# Offense count: 1102 +# Offense count: 931 # Configuration parameters: AssignmentOnly. RSpec/InstanceVariable: Exclude: @@ -342,6 +352,7 @@ RSpec/InstanceVariable: - 'spec/searchworks_title_spec.rb' # Offense count: 2 +# Cop supports --auto-correct. RSpec/LetBeforeExamples: Exclude: - 'spec/origin_info_spec.rb' @@ -357,7 +368,7 @@ RSpec/MultipleDescribes: Exclude: - 'spec/geo_spatial_spec.rb' -# Offense count: 114 +# Offense count: 100 # Configuration parameters: AggregateFailuresByDefault. RSpec/MultipleExpectations: Max: 9 @@ -367,7 +378,7 @@ RSpec/NamedSubject: Exclude: - 'spec/lib/stanford-mods/coordinate_spec.rb' -# Offense count: 38 +# Offense count: 36 RSpec/NestedGroups: Max: 5 @@ -409,7 +420,7 @@ Style/BlockDelimiters: - 'lib/stanford-mods/searchworks_subjects.rb' - 'spec/name_spec.rb' -# Offense count: 67 +# Offense count: 65 Style/CommentedKeyword: Exclude: - 'lib/stanford-mods.rb' @@ -509,6 +520,11 @@ Style/MultilineTernaryOperator: Exclude: - 'lib/stanford-mods/physical_location.rb' +# Offense count: 1 +Style/MultipleComparison: + Exclude: + - 'lib/stanford-mods/origin_info.rb' + # Offense count: 1 # Cop supports --auto-correct. # Configuration parameters: EnforcedOctalStyle. @@ -517,6 +533,15 @@ Style/NumericLiteralPrefix: Exclude: - 'spec/date_parsing_spec.rb' +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. +# SupportedStyles: predicate, comparison +Style/NumericPredicate: + Exclude: + - 'spec/**/*' + - 'lib/stanford-mods/searchworks.rb' + # Offense count: 8 # Cop supports --auto-correct. Style/PerlBackrefs: @@ -599,7 +624,7 @@ Style/UnneededCondition: - 'lib/stanford-mods/origin_info.rb' - 'lib/stanford-mods/searchworks.rb' -# Offense count: 125 +# Offense count: 124 # Cop supports --auto-correct. # Configuration parameters: MinSize, WordRegex. # SupportedStyles: percent, brackets diff --git a/Gemfile b/Gemfile index 26c1f94..243cfc9 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ source 'https://rubygems.org' gemspec group :test, :development do - gem 'rubocop', require: false + gem 'rubocop', '~> 0.60.0', require: false gem 'rubocop-rspec', require: false gem 'pry-byebug', require: false, platform: [:ruby_20, :ruby_21] gem 'coveralls', require: false diff --git a/lib/stanford-mods/coordinate.rb b/lib/stanford-mods/coordinate.rb index c32b846..f6c6b03 100644 --- a/lib/stanford-mods/coordinate.rb +++ b/lib/stanford-mods/coordinate.rb @@ -16,12 +16,14 @@ def initialize(value) # @return [String] the coordinate in WKT/CQL ENVELOPE representation def as_envelope return unless valid? + "ENVELOPE(#{bounds[:min_x]}, #{bounds[:max_x]}, #{bounds[:max_y]}, #{bounds[:min_y]})" end # @return [String] the coordinate in Solr 4.x+ bbox-format representation def as_bbox return unless valid? + "#{bounds[:min_x]} #{bounds[:min_y]} #{bounds[:max_x]} #{bounds[:max_y]}" end @@ -44,6 +46,7 @@ def bounds @bounds ||= begin matches = cleaner_coordinate(value).match %r{\A(?[EW].+-+.+)\s*/\s*(?[NS].+-+.+)\Z} return {} unless matches + min_x, max_x = matches['lat'].split(/-+/).map { |x| coord_to_decimal(x) }.minmax min_y, max_y = matches['lng'].split(/-+/).map { |y| coord_to_decimal(y) }.minmax { min_x: min_x, min_y: min_y, max_x: max_x, max_y: max_y } diff --git a/lib/stanford-mods/date_parsing.rb b/lib/stanford-mods/date_parsing.rb index 767d8cc..6b094f5 100644 --- a/lib/stanford-mods/date_parsing.rb +++ b/lib/stanford-mods/date_parsing.rb @@ -32,6 +32,7 @@ def self.sortable_year_string_from_date_str(date_str) # @return [Boolean] true if the year is between -999 and (current year + 1); false otherwise def self.year_str_valid?(year_str) return false unless year_str && (year_str.match(/^\d{1,4}$/) || year_str.match(/^-\d{1,3}$/)) + (-1000 < year_str.to_i) && (year_str.to_i < Date.today.year + 2) end @@ -39,6 +40,7 @@ def self.year_str_valid?(year_str) # @return [Boolean] true if the year is between -9999 and (current year + 1); false otherwise def self.year_int_valid?(year) return false unless year.is_a? Integer + (-1000 < year.to_i) && (year < Date.today.year + 2) end @@ -59,6 +61,7 @@ def date_str_for_display return display_str_for_bc if orig_date_str.match(BC_REGEX) # decade next in case there are 4 digits, e.g. 1950s return display_str_for_decade if orig_date_str.match(DECADE_4CHAR_REGEXP) || orig_date_str.match(DECADE_S_REGEXP) + result = sortable_year_for_yyyy_or_yy unless result # try removing brackets between digits in case we have 169[5] or [18]91 @@ -81,6 +84,7 @@ def year_int_from_date_str return if orig_date_str == '0000-00-00' # shpc collection has these useless dates # B.C. first in case there are 4 digits, e.g. 1600 B.C. return sortable_year_int_for_bc if orig_date_str.match(BC_REGEX) + result = sortable_year_for_yyyy_or_yy result ||= sortable_year_for_decade # 19xx or 20xx result ||= sortable_year_for_century @@ -102,6 +106,7 @@ def sortable_year_string_from_date_str return if orig_date_str == '0000-00-00' # shpc collection has these useless dates # B.C. first in case there are 4 digits, e.g. 1600 B.C. return sortable_year_str_for_bc if orig_date_str.match(BC_REGEX) + result = sortable_year_for_yyyy_or_yy result ||= sortable_year_for_decade # 19xx or 20xx result ||= sortable_year_for_century @@ -144,6 +149,7 @@ def sortable_year_for_yyyy # @return [String, nil] 4 digit year (e.g. 1865, 0950) if orig_date_str matches pattern, nil otherwise def sortable_year_for_yy return unless orig_date_str + slash_matches = orig_date_str.match(/\d{1,2}\/\d{1,2}\/\d{2}/) if slash_matches date_obj = Date.strptime(orig_date_str, '%m/%d/%y') @@ -196,6 +202,7 @@ def display_str_for_decade def sortable_year_for_century return unless orig_date_str return if orig_date_str =~ /B\.C\./ + century_matches = orig_date_str.match(CENTURY_4CHAR_REGEXP) if century_matches return $1 + '00' if $1.length == 2 @@ -215,6 +222,7 @@ def sortable_year_for_century def display_str_for_century return unless orig_date_str return if orig_date_str =~ /B\.C\./ + century_str_matches = orig_date_str.match(CENTURY_WORD_REGEXP) return century_str_matches.to_s if century_str_matches @@ -262,6 +270,7 @@ def display_str_for_bc # @return [String, nil] String sortable -ddd if orig_date_str matches pattern; nil otherwise def sortable_year_str_for_early_numeric return unless orig_date_str.match(EARLY_NUMERIC) + if orig_date_str =~ /^\-/ # negative number becomes x - 1000 for sorting; -005 for -995 num = orig_date_str[1..-1].to_i - 1000 @@ -275,6 +284,7 @@ def sortable_year_str_for_early_numeric # @return [Integer, nil] Integer sortable -ddd if orig_date_str matches pattern; nil otherwise def sortable_year_int_for_early_numeric return orig_date_str.to_i if orig_date_str.match(EARLY_NUMERIC) + orig_date_str.to_i if orig_date_str =~ /^-\d{4}$/ end @@ -290,6 +300,7 @@ def display_str_for_early_numeric return '1 B.C.' if orig_date_str == '0' # negative number becomes B.C. return "#{orig_date_str[1..-1].to_i + 1} B.C." if orig_date_str =~ /^\-/ + # remove leading 0s from early dates "#{orig_date_str.to_i} A.D." end @@ -304,6 +315,7 @@ def year_via_ruby_parsing # need more in string than only 2 digits return if orig_date_str.match(/^\d\d$/) || orig_date_str.match(/^\D*\d\d\D*$/) return if orig_date_str =~ /\d\s*B.C./ # skip B.C. dates + date_obj = Date.parse(orig_date_str) date_obj.year.to_s rescue ArgumentError diff --git a/lib/stanford-mods/imprint.rb b/lib/stanford-mods/imprint.rb index 005e306..4427091 100644 --- a/lib/stanford-mods/imprint.rb +++ b/lib/stanford-mods/imprint.rb @@ -45,6 +45,7 @@ def publication_date_for_slider else date_field_keys.map do |date_field| next unless origin_info_node.respond_to?(date_field) + date_elements = origin_info_node.send(date_field) date_elements.map(&:as_object).map(&:first) if date_elements.any? end.first @@ -82,6 +83,7 @@ def compact_and_join_with_delimiter(values, delimiter) compact_values = values.compact.reject { |v| v.strip.empty? } return compact_values.join(delimiter) if compact_values.length == 1 || !ends_in_terminating_punctuation?(delimiter) + compact_values.each_with_index.map do |value, i| if (compact_values.length - 1) == i || # last item? ends_in_terminating_punctuation?(value) @@ -104,6 +106,7 @@ def edition_vals_str(origin_info_node) def publisher_vals_str(origin_info_node) return if origin_info_node.publisher.text.strip.empty? + publishers = origin_info_node.publisher.reject do |p| p.text.strip.empty? end.map(&:text) @@ -114,6 +117,7 @@ def publisher_vals_str(origin_info_node) def place_vals_str(origin_info_node) return if origin_info_node.place.text.strip.empty? + places = place_terms(origin_info_node).reject do |p| p.text.strip.empty? end.map(&:text) @@ -130,6 +134,7 @@ def unencoded_place_terms?(element) def place_terms(origin_info_element) return [] unless origin_info_element.respond_to?(:place) && origin_info_element.place.respond_to?(:placeTerm) + if unencoded_place_terms?(origin_info_element) origin_info_element.place.placeTerm.select do |term| !term.attributes['type'].respond_to?(:value) || @@ -142,6 +147,7 @@ def place_terms(origin_info_element) term.attributes['authority'].respond_to?(:value) && term.attributes['authority'].value == 'marccountry' && MARC_COUNTRIES.include?(term.text.strip) + term = term.clone term.content = MARC_COUNTRIES[term.text.strip] term @@ -154,12 +160,14 @@ def place_terms(origin_info_element) def date_str(origin_info_node) date_vals = origin_info_date_vals(origin_info_node) return if date_vals.empty? + date_vals.map(&:strip).join(' ') end def origin_info_date_vals(origin_info_node) date_field_keys.map do |date_field| next unless origin_info_node.respond_to?(date_field) + date_elements = origin_info_node.send(date_field) date_elements_display_vals(date_elements) if date_elements.present? end.compact.flatten @@ -338,8 +346,8 @@ def process_w3cdtf_date(ng_date_element) else ng_date_element.content end - rescue - ng_date_element.content + rescue + ng_date_element.content end ng_date_element end @@ -352,8 +360,8 @@ def process_iso8601_date(ng_date_element) else ng_date_element.content end - rescue - ng_date_element.content + rescue + ng_date_element.content end ng_date_element end @@ -376,8 +384,8 @@ def process_decade_date(ng_date_element) else my_ng_date_element.content end - rescue - my_ng_date_element.content + rescue + my_ng_date_element.content end my_ng_date_element end @@ -398,8 +406,8 @@ def process_century_date(ng_date_element) else my_ng_date_element.content end - rescue - my_ng_date_element.content + rescue + my_ng_date_element.content end my_ng_date_element end diff --git a/lib/stanford-mods/name.rb b/lib/stanford-mods/name.rb index 3a01baf..baad246 100644 --- a/lib/stanford-mods/name.rb +++ b/lib/stanford-mods/name.rb @@ -45,6 +45,7 @@ def non_collector_person_authors result = [] mods_ng_xml.personal_name.map do |n| next if n.role.size.zero? + n.role.each { |r| result << n.display_value_w_date unless includes_marc_relator_collector_role?(r) } @@ -58,6 +59,7 @@ def collectors_w_dates result = [] mods_ng_xml.personal_name.each do |n| next if n.role.size.zero? + n.role.each { |r| result << n.display_value_w_date if includes_marc_relator_collector_role?(r) } diff --git a/lib/stanford-mods/origin_info.rb b/lib/stanford-mods/origin_info.rb index 0fb04b1..438927a 100644 --- a/lib/stanford-mods/origin_info.rb +++ b/lib/stanford-mods/origin_info.rb @@ -82,6 +82,7 @@ def imprint_display_str def year_display_str(date_el_array) result = date_parsing_result(date_el_array, :date_str_for_display) return result if result + _ignore, orig_str_to_parse = self.class.earliest_year_str(date_el_array) DateParsing.date_str_for_display(orig_str_to_parse) if orig_str_to_parse end @@ -93,6 +94,7 @@ def year_display_str(date_el_array) def year_int(date_el_array) result = date_parsing_result(date_el_array, :year_int_from_date_str) return result if result + year_int, _ignore = self.class.earliest_year_int(date_el_array) year_int if year_int end @@ -104,6 +106,7 @@ def year_int(date_el_array) def year_sort_str(date_el_array) result = date_parsing_result(date_el_array, :sortable_year_string_from_date_str) return result if result + sortable_str, _ignore = self.class.earliest_year_str(date_el_array) sortable_str if sortable_str end @@ -115,6 +118,7 @@ def year_sort_str(date_el_array) def date_created_elements(ignore_approximate = false) date_created_nodeset = mods_ng_xml.origin_info.dateCreated return self.class.remove_approximate(date_created_nodeset) if ignore_approximate + date_created_nodeset.to_a end @@ -125,6 +129,7 @@ def date_created_elements(ignore_approximate = false) def date_issued_elements(ignore_approximate = false) date_issued_nodeset = mods_ng_xml.origin_info.dateIssued return self.class.remove_approximate(date_issued_nodeset) if ignore_approximate + date_issued_nodeset.to_a end @@ -194,6 +199,7 @@ def single_pub_year(ignore_approximate, method_sym) # @return [Integer, String] year as a String or Integer, depending on method_sym def date_parsing_result(date_el_array, method_sym) return if date_el_array.empty? + # prefer keyDate key_date_el = self.class.keyDate(date_el_array) DateParsing.send(method_sym, key_date_el.content) if key_date_el @@ -239,6 +245,7 @@ def pub_date_facet return nil unless pub_date return "#{pub_date.to_i + 1000} B.C." if pub_date.start_with?('-') return pub_date unless pub_date.include? '--' + "#{pub_date[0, 2].to_i + 1}th century" end @@ -251,6 +258,7 @@ def pub_date_sort pd = pd.gsub('--', '00') end fail "pub_date_sort was about to return a non 4 digit value #{pd}!" if pd && pd.length != 4 + pd end @@ -261,6 +269,7 @@ def pub_date_sort def pub_date_display return dates_no_marc_encoding.first unless dates_no_marc_encoding.empty? return dates_marc_encoding.first unless dates_marc_encoding.empty? + nil end @@ -274,6 +283,7 @@ def pub_year # use the cached year if there is one if @pub_year return nil if @pub_year == '' + return @pub_year end @@ -307,6 +317,7 @@ def pub_year def pub_dates return dates_marc_encoding unless dates_marc_encoding.empty? return dates_no_marc_encoding unless dates_no_marc_encoding.empty? + nil end @@ -410,6 +421,7 @@ def get_single_digit_century(dates) dates.each do |f_date| matches = f_date.scan(/\d{1}th/) next if matches.empty? + if matches.length == 1 @pub_year = (matches.first[0, 2].to_i - 1).to_s + '--' return @pub_year @@ -436,6 +448,7 @@ def get_double_digit_century(dates) dates.each do |f_date| matches = f_date.scan(/\d{2}th/) next if matches.empty? + if matches.length == 1 @pub_year = (matches.first[0, 2].to_i - 1).to_s + '--' return @pub_year @@ -464,6 +477,7 @@ def get_u_year(dates) # Single digit u notation matches = f_date.scan(/\d{3}u/) return matches.first.tr('u', '0') if matches.length == 1 + # Double digit u notation matches = f_date.scan(/\d{2}u{2}/) return matches.first.tr('u', '-') if matches.length == 1 diff --git a/lib/stanford-mods/searchworks.rb b/lib/stanford-mods/searchworks.rb index a7fad16..4c1199a 100644 --- a/lib/stanford-mods/searchworks.rb +++ b/lib/stanford-mods/searchworks.rb @@ -179,6 +179,7 @@ def sw_full_title result = parts ? preParts + ". " + parts : preParts return nil unless result + result += "." unless result =~ /[[:punct:]]$/ result.strip! result = nil if result.empty? @@ -192,6 +193,7 @@ def sw_full_title def sw_title_display result = sw_full_title return nil unless result + result.sub(/[\.,;:\/\\]+$/, '').strip end @@ -236,6 +238,7 @@ def sw_full_title_without_commas def format_main types = typeOfResource return [] unless types + article_genres = ['article', 'Article', 'book chapter', 'Book chapter', 'Book Chapter', 'issue brief', 'Issue brief', 'Issue Brief', @@ -296,6 +299,7 @@ def format_main 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? @@ -315,6 +319,7 @@ def sw_genre 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 diff --git a/lib/stanford-mods/searchworks_subjects.rb b/lib/stanford-mods/searchworks_subjects.rb index 6a19775..3b16413 100644 --- a/lib/stanford-mods/searchworks_subjects.rb +++ b/lib/stanford-mods/searchworks_subjects.rb @@ -109,12 +109,14 @@ def geographic_search if codes && codes.size > xvals.size subject.geographicCode.each { |n| next unless n.authority != 'marcgac' && n.authority != 'marccountry' + sw_logger.info("#{druid} has subject geographicCode element with untranslated encoding (#{n.authority}): #{n.to_xml}") } end # FIXME: stanford-mods should be returning [], not nil ... return nil if !result || result.empty? + result end end diff --git a/spec/date_parsing_spec.rb b/spec/date_parsing_spec.rb index 0923e85..2eaf583 100644 --- a/spec/date_parsing_spec.rb +++ b/spec/date_parsing_spec.rb @@ -394,12 +394,14 @@ Stanford::Mods::DateParsing.date_str_for_display('1666') end end + context '*sortable_year_string_from_date_str' do it 'calls instance method sortable_year_string_from_date_str' do expect_any_instance_of(Stanford::Mods::DateParsing).to receive(:sortable_year_string_from_date_str) Stanford::Mods::DateParsing.sortable_year_string_from_date_str('1666') end end + context '*year_int_from_date_str' do it 'calls instance method year_int_from_date_str' do expect_any_instance_of(Stanford::Mods::DateParsing).to receive(:year_int_from_date_str) diff --git a/spec/imprint_spec.rb b/spec/imprint_spec.rb index 17278b5..de3cd75 100644 --- a/spec/imprint_spec.rb +++ b/spec/imprint_spec.rb @@ -30,6 +30,7 @@ def stanford_mods_imprint(smods_rec) end end end + describe 'bad dates' do it 'ignores bad date values' do smods_rec.from_str(mods_origin_info_start_str + diff --git a/spec/name_spec.rb b/spec/name_spec.rb index 7adafe1..ad2b48c 100644 --- a/spec/name_spec.rb +++ b/spec/name_spec.rb @@ -284,6 +284,7 @@ expect(smods_rec.non_collector_person_authors).to eq [name] end end + it 'nil if only collectors' do name_snippet = <<-EOF @@ -345,6 +346,7 @@ expect(smods_rec.collectors_w_dates).to eq [collector_name] end end + context 'no valueURI for roleTerm' do it 'collector marc relator code' do name_snippet = @@ -373,6 +375,7 @@ expect(smods_rec.collectors_w_dates).to eq [collector_name] end end + it 'does not include non-collectors' do name_snippet = <<-EOF diff --git a/spec/origin_info_spec.rb b/spec/origin_info_spec.rb index b2e8e30..8a812fb 100644 --- a/spec/origin_info_spec.rb +++ b/spec/origin_info_spec.rb @@ -66,6 +66,7 @@ SPOTLIGHT_PUB_DATE_DATA.each_pair.each do |coll_name, coll_data| # papyri - the only Spotlight data with BC dates next if coll_name == 'papyri' && method_sym == :pub_year_int + coll_data.each_pair do |mods_str, exp_vals| expected = exp_vals[exp_val_position] it "#{expected} for rec in #{coll_name}" do @@ -303,6 +304,7 @@ end end end + context "retains element when attribute qualifer=" do ['inferred', 'invalid_attr_val'].each do |attr_val| let(:qual_attr_val) { attr_val } @@ -372,6 +374,7 @@ end end end + context "retains element when attribute qualifer=" do ['inferred', 'invalid_attr_val'].each do |attr_val| let(:qual_attr_val) { attr_val } diff --git a/spec/physical_location_spec.rb b/spec/physical_location_spec.rb index 80e522c..0e77180 100644 --- a/spec/physical_location_spec.rb +++ b/spec/physical_location_spec.rb @@ -74,6 +74,7 @@ expect(@smods_rec.box).to eq expected end end + context 'in /relatedItem/location/physicalLocation' do it "has the expected box label '#{expected}'" do @smods_rec.from_str(mods_rel_item_loc_phys_loc) @@ -131,6 +132,7 @@ expect(@smods_rec.folder).to eq expected end end + context 'in /relatedItem/location/physicalLocation' do it "has the expected folder label '#{expected}'" do @smods_rec.from_str(mods_rel_item_loc_phys_loc) @@ -179,12 +181,14 @@ expect(@smods_rec.physical_location_str).to eq expected end end + context 'in /relatedItem/location/physicalLocation' do it "has the expected location '#{expected}'" do @smods_rec.from_str(mods_rel_item_loc_phys_loc) expect(@smods_rec.physical_location_str).to eq expected end end + context 'with multiple physicalLocation elements' do it "has the expected location '#{expected}'" do @smods_rec.from_str(mods_loc_multiple_phys_loc) @@ -233,12 +237,14 @@ expect(@smods_rec.series).to eq expected end end + context 'in /relatedItem/location/physicalLocation' do it "has the expected series name '#{expected}'" do @smods_rec.from_str(mods_rel_item_loc_phys_loc) expect(@smods_rec.series).to eq expected end end + context 'with multiple physicalLocation elements' do it "has the expected series name '#{expected}'" do @smods_rec.from_str(mods_loc_multiple_phys_loc) diff --git a/spec/searchworks_pub_dates_spec.rb b/spec/searchworks_pub_dates_spec.rb index af28ecf..78a51c0 100644 --- a/spec/searchworks_pub_dates_spec.rb +++ b/spec/searchworks_pub_dates_spec.rb @@ -212,6 +212,7 @@ expect(smods_rec.send(:pub_date)).to eq('8--') end end # pub_date + context "pub_dates (protected)" do it "puts dateIssued values before dateCreated values" do m = " diff --git a/spec/searchworks_spec.rb b/spec/searchworks_spec.rb index c5f21e0..9b39d17 100644 --- a/spec/searchworks_spec.rb +++ b/spec/searchworks_spec.rb @@ -97,6 +97,7 @@ " @smods_rec.from_str(m) end + it "main author (for author_1xx_search)" do expect(@smods_rec).to receive(:main_author_w_date) # in stanford-mods.rb @smods_rec.sw_main_author diff --git a/spec/searchworks_subject_raw_spec.rb b/spec/searchworks_subject_raw_spec.rb index bd6b8a7..d682b12 100644 --- a/spec/searchworks_subject_raw_spec.rb +++ b/spec/searchworks_subject_raw_spec.rb @@ -128,6 +128,7 @@ " @smods_rec.from_str m end + it "uses a ', ' as the separator by default" do expect(@smods_rec.sw_subject_names).to eq ['first, second'] end @@ -192,6 +193,7 @@ " @smods_rec.from_str m end + it "uses a ' ' as the separator by default" do expect(@smods_rec.sw_subject_titles).to eq ['first second'] end @@ -276,6 +278,7 @@ expect(@smods_rec.sw_geographic_search).to eq([]) end end + context "hierarchicalGeographic subelement" do it "should have a separate value for each hierarchicalGeographic element" do m = " @@ -305,6 +308,7 @@ " @smods_rec.from_str m end + it "uses a space as the separator by default" do expect(@smods_rec.sw_geographic_search).to eq ['Canada British Columbia Vancouver'] end @@ -313,6 +317,7 @@ end end end # hierarchicalGeographic + context "geographicCode subelement" do before(:all) do m = " @@ -324,6 +329,7 @@ @smods_rec.from_str m @geo_search_from_codes = @smods_rec.sw_geographic_search end + it "should not add untranslated values" do expect(@geo_search_from_codes).not_to include('n-us-md') expect(@geo_search_from_codes).not_to include('e-er') diff --git a/spec/searchworks_subject_spec.rb b/spec/searchworks_subject_spec.rb index 8392e13..31a3497 100644 --- a/spec/searchworks_subject_spec.rb +++ b/spec/searchworks_subject_spec.rb @@ -240,6 +240,7 @@ expect(@smods_rec.subject_other_subvy_search).to be_nil end end + context "genre subelement" do it "should have a separate value for each genre element" do m = " @@ -266,6 +267,7 @@ before :each do allow(@smods_rec.sw_logger).to receive(:info).with(/ has subject geographicCode element with untranslated encoding \(iso3166\): us<\/geographicCode>/) end + it "should be nil if there are no values in the MODS" do @smods_rec = Stanford::Mods::Record.new @smods_rec.from_str(@ng_mods_no_subject.to_s) diff --git a/spec/searchworks_title_spec.rb b/spec/searchworks_title_spec.rb index ee050af..4788e07 100644 --- a/spec/searchworks_title_spec.rb +++ b/spec/searchworks_title_spec.rb @@ -93,6 +93,7 @@ expect(@smods_rec.sw_full_title).to eq 'The Olympics!' end end # no subtitle + context 'subtitle' do it 'end title with a colon' do m = " @@ -136,6 +137,7 @@ expect(@smods_rec.sw_full_title).to eq 'The Olympics : a history?' end end # subtitle + context 'partName' do context 'no partNumber' do it 'end partName with period' do @@ -175,6 +177,7 @@ expect(@smods_rec.sw_full_title).to eq 'cfb. Appendix.' end end # no partNumber + context 'partNumber' do it 'end partNumber with comma' do m = " @@ -218,6 +221,7 @@ end end end # partName + context 'no partName, but partNumber' do it 'end partNumber with period' do m = " @@ -335,6 +339,7 @@ expect(@smods_rec.sw_title_display).to eq 'The Jerk' end end + context 'no subtitle' do it 'end title with a period' do m = " @@ -364,6 +369,7 @@ expect(@smods_rec.sw_title_display).to eq 'The Olympics!' end end # no subtitle + context 'subtitle' do it 'end title with a colon' do m = " @@ -407,6 +413,7 @@ expect(@smods_rec.sw_title_display).to eq 'The Olympics : a history?' end end # subtitle + context 'partName' do context 'no partNumber' do it 'end partName with period' do @@ -446,6 +453,7 @@ expect(@smods_rec.sw_title_display).to eq 'cfb. Appendix' end end # no partNumber + context 'partNumber' do it 'end partNumber with comma' do m = " @@ -489,6 +497,7 @@ end end end # partName + context 'no partName, but partNumber' do it 'end partNumber with period' do m = " @@ -557,6 +566,7 @@ @smods_rec.from_str(m) @addl_titles = @smods_rec.sw_addl_titles end + it 'should not include the main title' do expect(@addl_titles.size).to eq 2 expect(@addl_titles).not_to include(@smods_rec.sw_full_title) @@ -643,6 +653,7 @@ " @all_smods_rec.from_str(all) end + it 'short titles' do expect(@mccarthy_smods_rec.sw_short_title).to eql 'McCarthy, John' expect(@insp_general_smods_rec.sw_short_title).to eql 'Semiannual report to Congress'