lib/stanford-mods/searchworks.rb in stanford-mods-0.0.22 vs lib/stanford-mods/searchworks.rb in stanford-mods-0.0.23
- old
+ new
@@ -387,19 +387,20 @@
else
vals = self.term_values([:origin_info,:dateCreated])
end
vals and vals.empty? ? nil : vals
end
+
def is_number?(object)
true if Integer(object) rescue false
end
def is_date?(object)
true if Date.parse(object) rescue false
end
# Get the publish year from mods
- #@return [String] 4 character year or nil if no valid date was found
+ # @return [String] 4 character year or nil if no valid date was found
def pub_year
#use the cached year if there is one
if @pub_year
if @pub_year == ''
return nil
@@ -415,10 +416,13 @@
pruned_dates << f_date.gsub('?','').gsub('[','').gsub(']','')
end
#try to find a date starting with the most normal date formats and progressing to more wonky ones
@pub_year=get_plain_four_digit_year pruned_dates
return @pub_year if @pub_year
+ # Check for years in u notation, e.g., 198u
+ @pub_year=get_u_year pruned_dates
+ return @pub_year if @pub_year
@pub_year=get_double_digit_century pruned_dates
return @pub_year if @pub_year
@pub_year=get_bc_year pruned_dates
return @pub_year if @pub_year
@pub_year=get_three_digit_year pruned_dates
@@ -561,9 +565,28 @@
@pub_year=match
return match
end
end
return matches.first
+ end
+ end
+ return nil
+ end
+
+ # If a year has a "u" in it, replace instances of u with 0
+ # @param [String]
+ # @return String
+ def get_u_year dates
+ dates.each do |f_date|
+ # Single digit u notation
+ matches=f_date.scan(/\d{3}u/)
+ if matches.length == 1
+ return matches.first.gsub('u','0')
+ end
+ # Double digit u notation
+ matches=f_date.scan(/\d{2}u{2}/)
+ if matches.length == 1
+ return matches.first.gsub('u','-')
end
end
return nil
end