Module: CocinaDisplay::Concerns::Events
- Included in:
- CocinaDisplay::CocinaRecord
- Defined in:
- lib/cocina_display/concerns/events.rb
Instance Method Summary collapse
-
#earliest_preferred_date(dates, ignore_qualified: false) ⇒ CocinaDisplay::Dates::Date?
Choose the earliest, best date from a provided list of event dates.
-
#event_dates ⇒ Array<CocinaDisplay::Dates::Date>
All dates associated with the object via an event.
-
#events ⇒ Array<CocinaDisplay::Events::Event>
All events associated with the object.
-
#imprint_display_str ⇒ String?
String for displaying the imprint statement(s).
-
#imprint_events ⇒ Array<CocinaDisplay::Imprint>
Array of CocinaDisplay::Imprint objects for all relevant Cocina events.
-
#pub_date(ignore_qualified: false) ⇒ CocinaDisplay::Dates::Date?
The earliest preferred publication date as a CocinaDisplay::Dates::Date object.
-
#pub_date_edtf(ignore_qualified: false) ⇒ Date?
The earliest preferred publication date as a Date object.
-
#pub_year_display_str(ignore_qualified: false) ⇒ String?
String for displaying the earliest preferred publication year or range.
-
#pub_year_int(ignore_qualified: false) ⇒ Integer?
The earliest preferred publication year as an integer.
-
#pub_year_int_range(ignore_qualified: false) ⇒ Array<Integer>?
The range of preferred publication years as an array of integers.
-
#publication_events ⇒ Array<CocinaDisplay::Events::Event>
All events that could be used to select a publication date.
-
#publication_places ⇒ Array<String>
List of places of publication as strings.
Instance Method Details
#earliest_preferred_date(dates, ignore_qualified: false) ⇒ CocinaDisplay::Dates::Date?
Choose the earliest, best date from a provided list of event dates. Rules to consider:
-
Reject any dates that were not parsed.
-
If ‘ignore_qualified` is true, reject any qualified dates.
-
If there are any primary dates, prefer those dates.
-
If there are any encoded dates, prefer those dates.
-
From whatever is left, choose the earliest date.
151 152 153 154 155 156 157 158 159 160 |
# File 'lib/cocina_display/concerns/events.rb', line 151 def earliest_preferred_date(dates, ignore_qualified: false) return nil if dates.empty? dates.filter!(&:parsed_date?) dates.reject!(&:approximate?) if ignore_qualified dates = dates.filter(&:primary?).presence || dates dates = dates.filter(&:encoding?).presence || dates dates.min end |
#event_dates ⇒ Array<CocinaDisplay::Dates::Date>
All dates associated with the object via an event.
120 121 122 |
# File 'lib/cocina_display/concerns/events.rb', line 120 def event_dates @event_dates ||= events.flat_map(&:dates) end |
#events ⇒ Array<CocinaDisplay::Events::Event>
All events associated with the object.
91 92 93 |
# File 'lib/cocina_display/concerns/events.rb', line 91 def events @events ||= path("$.description.event.*").map { |event| CocinaDisplay::Events::Event.new(event) } end |
#imprint_display_str ⇒ String?
String for displaying the imprint statement(s).
78 79 80 |
# File 'lib/cocina_display/concerns/events.rb', line 78 def imprint_display_str imprint_events.map(&:display_str).compact_blank.join("; ") end |
#imprint_events ⇒ Array<CocinaDisplay::Imprint>
Array of CocinaDisplay::Imprint objects for all relevant Cocina events. Considers publication, creation, capture, and copyright events. Considers event types as well as date types if the event is untyped. Prefers events where the date was not encoded, if any.
108 109 110 111 112 113 114 115 116 |
# File 'lib/cocina_display/concerns/events.rb', line 108 def imprint_events imprints = events.filter do |event| event.has_any_type?("publication", "creation", "capture", "copyright") end.map do |event| CocinaDisplay::Events::Imprint.new(event.cocina) end imprints.reject(&:date_encoding?).presence || imprints end |
#pub_date(ignore_qualified: false) ⇒ CocinaDisplay::Dates::Date?
The earliest preferred publication date as a CocinaDisplay::Dates::Date object. Considers publication, creation, and capture dates in that order. Prefers dates marked as primary and those with a declared encoding.
130 131 132 133 134 135 136 137 138 |
# File 'lib/cocina_display/concerns/events.rb', line 130 def pub_date(ignore_qualified: false) pub_event_dates = event_dates.filter { |date| date.type == "publication" } creation_event_dates = event_dates.filter { |date| date.type == "creation" } capture_event_dates = event_dates.filter { |date| date.type == "capture" } [pub_event_dates, creation_event_dates, capture_event_dates].flat_map do |dates| earliest_preferred_date(dates, ignore_qualified: ignore_qualified) end.compact.first end |
#pub_date_edtf(ignore_qualified: false) ⇒ Date?
The earliest preferred publication date as a Date object. If the date was a range or interval, uses the start (or end if no start). Considers publication, creation, and capture dates in that order. Prefers dates marked as primary and those with a declared encoding.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/cocina_display/concerns/events.rb', line 16 def pub_date_edtf(ignore_qualified: false) date = pub_date(ignore_qualified: ignore_qualified) return unless date if date.is_a? CocinaDisplay::Dates::DateRange date = date.start || date.stop end edtf_date = date.date return unless edtf_date if edtf_date.is_a? EDTF::Interval edtf_date.from else edtf_date end end |
#pub_year_display_str(ignore_qualified: false) ⇒ String?
String for displaying the earliest preferred publication year or range. Considers publication, creation, and capture dates in that order. Prefers dates marked as primary and those with a declared encoding.
66 67 68 69 70 71 |
# File 'lib/cocina_display/concerns/events.rb', line 66 def pub_year_display_str(ignore_qualified: false) date = pub_date(ignore_qualified: ignore_qualified) return unless date date.decoded_value(allowed_precisions: [:year, :decade, :century]) end |
#pub_year_int(ignore_qualified: false) ⇒ Integer?
6 BCE will return -5; 4 CE will return 4.
The earliest preferred publication year as an integer. If the date was a range or interval, uses the start (or end if no start). Considers publication, creation, and capture dates in that order. Prefers dates marked as primary and those with a declared encoding.
41 42 43 |
# File 'lib/cocina_display/concerns/events.rb', line 41 def pub_year_int(ignore_qualified: false) pub_date_edtf(ignore_qualified: ignore_qualified)&.year end |
#pub_year_int_range(ignore_qualified: false) ⇒ Array<Integer>?
6 BCE will appear as -5; 4 CE will appear as 4.
The range of preferred publication years as an array of integers. Considers publication, creation, and capture dates in that order. Prefers dates marked as primary and those with a declared encoding.
51 52 53 54 55 56 57 |
# File 'lib/cocina_display/concerns/events.rb', line 51 def pub_year_int_range(ignore_qualified: false) date = pub_date(ignore_qualified: ignore_qualified) return unless date date = date.as_interval if date.is_a? CocinaDisplay::Dates::DateRange date.to_a.map(&:year).compact.uniq.sort end |
#publication_events ⇒ Array<CocinaDisplay::Events::Event>
All events that could be used to select a publication date. Includes publication, creation, and capture events. Considers event types as well as date types if the event is untyped.
99 100 101 |
# File 'lib/cocina_display/concerns/events.rb', line 99 def publication_events events.filter { |event| event.has_any_type?("publication", "creation", "capture") } end |
#publication_places ⇒ Array<String>
List of places of publication as strings. Considers locations for all publication, creation, and capture events.
85 86 87 |
# File 'lib/cocina_display/concerns/events.rb', line 85 def publication_places publication_events.flat_map { |event| event.locations.map(&:display_str) } end |