Module: Stanford::Mods::OriginInfo

Included in:
Record
Defined in:
lib/stanford-mods/concerns/origin_info.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.best_or_earliest_year(date_el_array) ⇒ Stanford::Mods::DateParsing

get earliest parseable year from the passed date elements

Parameters:

  • date_el_array (Array<Nokogiri::XML::Element>)

    the elements from which to select a pub date

Returns:



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_strString

Returns single String containing imprint information for display.

Returns:

  • (String)

    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

#imprintsArray<Stanford::Mods::Imprint>

Returns array of imprint objects.

Returns:



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’

Parameters:

  • node (Nokogiri::XML::Element)

    the date element

Returns:

  • (Boolean)


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

#placeObject



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

Parameters:

  • ignore_approximate (Boolean) (defaults to: false)

    true if approximate dates (per qualifier attribute) should be ignored; false if approximate dates should be included



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

Note:

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

Parameters:

  • ignore_approximate (Boolean) (defaults to: false)

    true if approximate dates (per qualifier attribute) should be ignored; false if approximate dates should be included

Returns:

  • (Integer)

    publication year as an Integer



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

Deprecated.

use pub_year_int

Note:

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

Parameters:

  • ignore_approximate (Boolean) (defaults to: false)

    true if approximate dates (per qualifier attribute) should be ignored; false if approximate dates should be included

Returns:

  • (String)

    single String containing publication year for lexical sorting



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