Module: Stanford::Mods::OriginInfo
- Included in:
- Record
- Defined in:
- lib/stanford-mods/concerns/origin_info.rb
Class Method Summary collapse
-
.best_or_earliest_year(date_el_array) ⇒ Stanford::Mods::DateParsing
get earliest parseable year from the passed date elements.
Instance Method Summary collapse
-
#imprint_display_str ⇒ String
Single String containing imprint information for display.
-
#imprints ⇒ Array<Stanford::Mods::Imprint>
Array of imprint objects.
-
#is_approximate(node) ⇒ Boolean
remove Elements from NodeSet if they have a qualifier attribute of ‘approximate’ or ‘questionable’.
- #place ⇒ Object
-
#pub_year_display_str(fields = [:dateIssued, :dateCreated, :dateCaptured], ignore_approximate: false) ⇒ Object
return a single string intended for display of pub year 0 < year < 1000: add A.D.
-
#pub_year_int(fields = [:dateIssued, :dateCreated, :dateCaptured], ignore_approximate: false) ⇒ Integer
return pub year as an Integer prefer dateIssued (any) before dateCreated (any) before dateCaptured (any) look for a keyDate and use it if there is one; otherwise pick earliest date.
-
#pub_year_sort_str(fields = [:dateIssued, :dateCreated, :dateCaptured], ignore_approximate: false) ⇒ String
deprecated
Deprecated.
use pub_year_int
Class Method Details
.best_or_earliest_year(date_el_array) ⇒ Stanford::Mods::DateParsing
get earliest parseable year from the passed date elements
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/stanford-mods/concerns/origin_info.rb', line 96 def self.best_or_earliest_year(date_el_array) key_dates, other_dates = date_el_array.partition { |node| node['keyDate'] == 'yes' } sortable_dates = key_dates.map { |x| DateParsing.new(x) }.select(&:sortable_year_string_from_date_str) sortable_dates = other_dates.map { |x| DateParsing.new(x) }.select(&:sortable_year_string_from_date_str) if sortable_dates.empty? results = {} # this is a little weird; instead of just the earliest sorting date, if there are multiple # dates with the same sort key, we want to make sure we get the last occurring one? sortable_dates.each do |v| results[v.sortable_year_string_from_date_str] = v end results[results.keys.min] end |
Instance Method Details
#imprint_display_str ⇒ String
Returns single String containing imprint information for display.
80 81 82 |
# File 'lib/stanford-mods/concerns/origin_info.rb', line 80 def imprint_display_str imprints.map(&:display_str).reject(&:empty?).join('; ') end |
#imprints ⇒ Array<Stanford::Mods::Imprint>
Returns array of imprint objects.
71 72 73 |
# File 'lib/stanford-mods/concerns/origin_info.rb', line 71 def imprints origin_info.map { |el| Stanford::Mods::Imprint.new(el) } end |
#is_approximate(node) ⇒ Boolean
remove Elements from NodeSet if they have a qualifier attribute of ‘approximate’ or ‘questionable’
88 89 90 91 |
# File 'lib/stanford-mods/concerns/origin_info.rb', line 88 def is_approximate(node) qualifier = node["qualifier"] if node.respond_to?('[]') qualifier == 'approximate' || qualifier == 'questionable' end |
#place ⇒ Object
75 76 77 |
# File 'lib/stanford-mods/concerns/origin_info.rb', line 75 def place term_values([:origin_info, :place, :placeTerm]) end |
#pub_year_display_str(fields = [:dateIssued, :dateCreated, :dateCaptured], ignore_approximate: false) ⇒ Object
return a single string intended for display of pub year 0 < year < 1000: add A.D. suffix year < 0: add B.C. suffix. (‘-5’ => ‘5 B.C.’, ‘700 B.C.’ => ‘700 B.C.’) 195u => 195x 19uu => 19xx
'-5' => '5 B.C.'
'700 B.C.' => '700 B.C.'
'7th century' => '7th century'
date ranges? prefer dateIssued (any) before dateCreated (any) before dateCaptured (any)
look for a keyDate and use it if there is one; otherwise pick earliest date
59 60 61 62 63 64 65 66 67 |
# File 'lib/stanford-mods/concerns/origin_info.rb', line 59 def pub_year_display_str(fields = [:dateIssued, :dateCreated, :dateCaptured], ignore_approximate: false) fields.each do |date_key| values = mods_ng_xml.origin_info.send(date_key) values = values.reject(&method(:is_approximate)) if ignore_approximate earliest_date = Stanford::Mods::OriginInfo.best_or_earliest_year(values) return earliest_date.date_str_for_display if earliest_date&.date_str_for_display end; nil end |
#pub_year_int(fields = [:dateIssued, :dateCreated, :dateCaptured], ignore_approximate: false) ⇒ Integer
for sorting: 5 B.C. => -5; 666 B.C. => -666
return pub year as an Integer prefer dateIssued (any) before dateCreated (any) before dateCaptured (any)
look for a keyDate and use it if there is one; otherwise pick earliest date
19 20 21 22 23 24 25 26 27 |
# File 'lib/stanford-mods/concerns/origin_info.rb', line 19 def pub_year_int(fields = [:dateIssued, :dateCreated, :dateCaptured], ignore_approximate: false) fields.each do |date_key| values = mods_ng_xml.origin_info.send(date_key) values = values.reject(&method(:is_approximate)) if ignore_approximate earliest_date = Stanford::Mods::OriginInfo.best_or_earliest_year(values) return earliest_date.year_int_from_date_str if earliest_date&.year_int_from_date_str end; nil end |
#pub_year_sort_str(fields = [:dateIssued, :dateCreated, :dateCaptured], ignore_approximate: false) ⇒ String
use pub_year_int
for string sorting 5 B.C. = -5 => -995; 6 B.C. => -994, so 6 B.C. sorts before 5 B.C.
return a single string intended for lexical sorting for pub date prefer dateIssued (any) before dateCreated (any) before dateCaptured (any)
look for a keyDate and use it if there is one; otherwise pick earliest date
36 37 38 39 40 41 42 43 44 |
# File 'lib/stanford-mods/concerns/origin_info.rb', line 36 def pub_year_sort_str(fields = [:dateIssued, :dateCreated, :dateCaptured], ignore_approximate: false) fields.each do |date_key| values = mods_ng_xml.origin_info.send(date_key) values = values.reject(&method(:is_approximate)) if ignore_approximate earliest_date = Stanford::Mods::OriginInfo.best_or_earliest_year(values) return earliest_date.sortable_year_string_from_date_str if earliest_date&.sortable_year_string_from_date_str end; nil end |