Module: CocinaDisplay::Concerns::Events

Included in:
CocinaDisplay::CocinaRecord, RelatedResource
Defined in:
lib/cocina_display/concerns/events.rb

Instance Method Summary collapse

Instance Method Details

#admin_creation_eventCocinaDisplay::Events::Event

The adminMetadata creation event (When was it was deposited?)



92
93
94
# File 'lib/cocina_display/concerns/events.rb', line 92

def admin_creation_event
  @admin_events ||= path("$.description.adminMetadata.event[?(@.type==\"creation\")]").map { |event| CocinaDisplay::Events::Event.new(event) }.first
end

#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:

  1. Reject any dates that were not parsed.

  2. If ‘ignore_qualified` is true, reject any qualified dates.

  3. If there are any primary dates, prefer those dates.

  4. If there are any encoded dates, prefer those dates.

  5. From whatever is left, choose the earliest date.

Parameters:

  • dates (Array<CocinaDisplay::Dates::Date>)

    The list of dates

  • ignore_qualified (Boolean) (defaults to: false)

    Reject qualified dates (e.g. approximate)

Returns:



164
165
166
167
168
169
170
171
172
173
# File 'lib/cocina_display/concerns/events.rb', line 164

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_date_display_dataArray<CocinaDisplay::DisplayData>

DisplayData for all dates associated with events.

Returns:



133
134
135
# File 'lib/cocina_display/concerns/events.rb', line 133

def event_date_display_data
  CocinaDisplay::DisplayData.from_objects(event_dates)
end

#event_datesArray<CocinaDisplay::Dates::Date>

All dates associated with the object via an event.

Returns:



121
122
123
# File 'lib/cocina_display/concerns/events.rb', line 121

def event_dates
  @event_dates ||= events.flat_map(&:dates)
end

#event_note_display_dataArray<CocinaDisplay::DisplayData>

DisplayData for all notes associated with events.

Returns:



127
128
129
# File 'lib/cocina_display/concerns/events.rb', line 127

def event_note_display_data
  CocinaDisplay::DisplayData.from_objects(events.flat_map(&:notes))
end

#eventsArray<CocinaDisplay::Events::Event>

All root level events associated with the object.

Returns:



86
87
88
# File 'lib/cocina_display/concerns/events.rb', line 86

def events
  @events ||= path("$.description.event.*").map { |event| CocinaDisplay::Events::Event.new(event) }
end

#imprint_eventsArray<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.

Returns:

  • (Array<CocinaDisplay::Imprint>)

    The list of Imprint objects



109
110
111
112
113
114
115
116
117
# File 'lib/cocina_display/concerns/events.rb', line 109

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

#imprint_strString?

String for displaying the imprint statement(s).

Examples:

CocinaRecord.fetch('bt553vr2845').imprint_str #=> "New York : Meridian Book, 1993, c1967"

Returns:

  • (String, nil)

See Also:

  • Imprint#to_s


73
74
75
# File 'lib/cocina_display/concerns/events.rb', line 73

def imprint_str
  imprint_events.map(&:to_s).compact_blank.join("; ")
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.

Parameters:

  • ignore_qualified (Boolean) (defaults to: false)

    Reject qualified dates (e.g. approximate)

Returns:



143
144
145
146
147
148
149
150
151
# File 'lib/cocina_display/concerns/events.rb', line 143

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.

Parameters:

  • ignore_qualified (Boolean) (defaults to: false)

    Reject qualified dates (e.g. approximate)

Returns:

  • (Date, nil)

See Also:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/cocina_display/concerns/events.rb', line 11

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_int(ignore_qualified: false) ⇒ Integer?

Note:

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.

Parameters:

  • ignore_qualified (Boolean) (defaults to: false)

    Reject qualified dates (e.g. approximate)

Returns:

  • (Integer, nil)


36
37
38
# File 'lib/cocina_display/concerns/events.rb', line 36

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>?

Note:

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.

Parameters:

  • ignore_qualified (Boolean) (defaults to: false)

    Reject qualified dates (e.g. approximate)

Returns:

  • (Array<Integer>, nil)


46
47
48
49
50
51
52
# File 'lib/cocina_display/concerns/events.rb', line 46

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

#pub_year_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.

Examples:

Year range

CocinaRecord.fetch('bb099mt5053').pub_year_str #=> "1932 - 2012"

Parameters:

  • ignore_qualified (Boolean) (defaults to: false)

    Reject qualified dates (e.g. approximate)

Returns:

  • (String, nil)


61
62
63
64
65
66
# File 'lib/cocina_display/concerns/events.rb', line 61

def pub_year_str(ignore_qualified: false)
  date = pub_date(ignore_qualified: ignore_qualified)
  return unless date

  date.decoded_value(allowed_precisions: [:year, :decade, :century])
end

#publication_eventsArray<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.

Returns:



100
101
102
# File 'lib/cocina_display/concerns/events.rb', line 100

def publication_events
  events.filter { |event| event.has_any_type?("publication", "creation", "capture") }
end

#publication_placesArray<String>

List of places of publication as strings. Considers locations for all publication, creation, and capture events.

Returns:

  • (Array<String>)


80
81
82
# File 'lib/cocina_display/concerns/events.rb', line 80

def publication_places
  publication_events.flat_map { |event| event.locations.map(&:to_s) }
end