lib/stanford-mods/searchworks.rb in stanford-mods-0.0.16 vs lib/stanford-mods/searchworks.rb in stanford-mods-0.0.17

- old
+ new

@@ -416,10 +416,12 @@ #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 @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 return @pub_year if @pub_year @pub_year=get_single_digit_century pruned_dates return @pub_year if @pub_year end @@ -451,22 +453,26 @@ end #Values for the pub date facet. This is less strict than the 4 year date requirements for pub_date #@return <Array[String]> with values for the pub date facet def pub_date_facet if pub_date + if pub_date.start_with?('-') + return (pub_date.to_i + 1000).to_s + ' B.C.' + end if pub_date.include? '--' cent=pub_date[0,2].to_i cent+=1 cent=cent.to_s+'th century' - cent + return cent else - pub_date + return pub_date end else nil end end + # Values are the contents of: # subject/topic # subject/name # subject/title @@ -589,9 +595,20 @@ def get_three_digit_year dates dates.each do |f_date| matches=f_date.scan(/\d{3}/) if matches.length > 0 return matches.first + end + end + return nil + end + #get the 3 digit BC year, return it as a negative, so -700 for 300 BC. Other methods will translate it to proper display, this is good for sorting. + def get_bc_year dates + dates.each do |f_date| + matches=f_date.scan(/\d{3} B.C./) + if matches.length > 0 + bc_year=matches.first[0..2] + return (bc_year.to_i-1000).to_s end end return nil end