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

- old
+ new

@@ -43,10 +43,11 @@ date_elements = if origin_info_node.as_object.first.key_dates.any? origin_info_node.as_object.first.key_dates.map(&:as_object).map(&:first) 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 end @@ -80,10 +81,11 @@ 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) value << ' ' else @@ -102,20 +104,22 @@ end.map(&:text).join(' ').strip end 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) compact_and_join_with_delimiter(publishers, ' : ') end # PLACE processing methods ------ 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) compact_and_join_with_delimiter(places, ' : ') end @@ -128,10 +132,11 @@ end 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) || term.attributes['type'].value == 'text' end.compact @@ -140,10 +145,11 @@ next unless term.attributes['type'].respond_to?(:value) && term.attributes['type'].value == 'code' && 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 end.compact end @@ -152,16 +158,18 @@ # DATE processing methods ------ 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 end @@ -336,12 +344,12 @@ elsif ng_date_element.text.strip =~ /^\d{4}-\d{2}$/ Date.parse("#{ng_date_element.text}-01").strftime(short_date_format) else ng_date_element.content end - rescue - ng_date_element.content + rescue + ng_date_element.content end ng_date_element end def process_iso8601_date(ng_date_element) @@ -350,12 +358,12 @@ if ng_date_element.text.strip =~ /^\d{8,}$/ Date.parse(ng_date_element.text).strftime(full_date_format) else ng_date_element.content end - rescue - ng_date_element.content + rescue + ng_date_element.content end ng_date_element end DECADE_4CHAR_REGEXP = Regexp.new('(^|.*\D)(\d{3}[u\-?x])(.*)') @@ -374,12 +382,12 @@ new_decade_str = "#{zeroth_year}s" if zeroth_year my_ng_date_element.content = "#{decade_matches[1]}#{new_decade_str}#{decade_matches[3]}" 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 CENTURY_4CHAR_REGEXP = Regexp.new('(^|.*\D)((\d{1,2})[u\-]{2})(.*)') @@ -396,11 +404,11 @@ new_century_str = "#{(century_matches[3].to_i + 1).ordinalize} century" my_ng_date_element.content = "#{century_matches[1]}#{new_century_str}#{century_matches[4]}" 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 def field_is_encoded?(ng_element, encoding)