Class: CocinaDisplay::Events::Event
- Inherits:
-
Object
- Object
- CocinaDisplay::Events::Event
- Includes:
- Comparable
- Defined in:
- lib/cocina_display/events/event.rb
Overview
An event associated with an object, like publication.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cocina ⇒ Object
readonly
Returns the value of attribute cocina.
Instance Method Summary collapse
- #<=>(other) ⇒ Integer?
-
#contributors ⇒ Array<CocinaDisplay::Contributor>
All contributors associated with this event.
-
#date_types ⇒ Array<String>
All types of dates associated with this event.
-
#dates ⇒ Array<CocinaDisplay::Dates::Date>
All dates associated with this event.
-
#has_any_type?(*match_types) ⇒ Boolean
True if the event or its dates have any of the provided types.
-
#has_type?(match_type) ⇒ Boolean
True if either the event type or any date type matches the given type.
-
#imprint? ⇒ Boolean
True if this event is likely to represent an imprint.
-
#initialize(cocina) ⇒ Event
constructor
Initialize the event with Cocina event data.
-
#label ⇒ String
The display label for the event.
-
#locations ⇒ Array<CocinaDisplay::Events::Location>
All locations associated with this event.
-
#notes ⇒ Array<CocinaDisplay::Events::Note>
All notes associated with this event.
-
#to_s ⇒ String
String representation of the event using date and location.
-
#type ⇒ String?
The declared type of the event, like “publication” or “creation”.
-
#types ⇒ Array<String>
Union of event’s type and its date types.
Constructor Details
#initialize(cocina) ⇒ Event
Initialize the event with Cocina event data.
11 12 13 |
# File 'lib/cocina_display/events/event.rb', line 11 def initialize(cocina) @cocina = cocina end |
Instance Attribute Details
#cocina ⇒ Object (readonly)
Returns the value of attribute cocina.
7 8 9 |
# File 'lib/cocina_display/events/event.rb', line 7 def cocina @cocina end |
Instance Method Details
#<=>(other) ⇒ Integer?
Also supports ‘event1.between?(event2, event3)` via Comparable.
Compare this CocinaDisplay::Events::Event to another CocinaDisplay::Events::Event using their Dates.
18 19 20 |
# File 'lib/cocina_display/events/event.rb', line 18 def <=>(other) [dates] <=> [other.dates] if other.is_a?(Event) end |
#contributors ⇒ Array<CocinaDisplay::Contributor>
All contributors associated with this event.
90 91 92 93 94 |
# File 'lib/cocina_display/events/event.rb', line 90 def contributors @contributors ||= Array(cocina["contributor"]).map do |contributor| CocinaDisplay::Contributors::Contributor.new(contributor) end end |
#date_types ⇒ Array<String>
This can differ from the top-level event type.
All types of dates associated with this event.
46 47 48 |
# File 'lib/cocina_display/events/event.rb', line 46 def date_types dates.map(&:type).uniq end |
#dates ⇒ Array<CocinaDisplay::Dates::Date>
The date types may differ from the underlying event type.
All dates associated with this event. Ignores known unparsable date values like “9999”. If the date is untyped, uses this event’s type as the date type.
69 70 71 72 73 74 75 76 |
# File 'lib/cocina_display/events/event.rb', line 69 def dates @dates ||= Array(cocina["date"]).filter_map do |date| CocinaDisplay::Dates::Date.from_cocina(date) end.filter(&:parsable?).map do |date| date.type ||= type date end end |
#has_any_type?(*match_types) ⇒ Boolean
True if the event or its dates have any of the provided types.
60 61 62 |
# File 'lib/cocina_display/events/event.rb', line 60 def has_any_type?(*match_types) match_types.any? { |type| has_type?(type) } end |
#has_type?(match_type) ⇒ Boolean
True if either the event type or any date type matches the given type.
53 54 55 |
# File 'lib/cocina_display/events/event.rb', line 53 def has_type?(match_type) types.include?(match_type) end |
#imprint? ⇒ Boolean
Unencoded dates or no dates often indicate an imprint statement.
True if this event is likely to represent an imprint.
81 82 83 84 85 86 |
# File 'lib/cocina_display/events/event.rb', line 81 def imprint? contributors.present? && locations.present? && (has_type?("publication") || types.empty?) && (dates.any? { |date| !date.encoding? } || dates.none?) end |
#label ⇒ String
The display label for the event. Uses “Imprint” if the event is likely to represent an imprint statement. If the event consists solely of a date, uses the date’s label. Capitalizes the event’s type, or its first date’s type if untyped.
27 28 29 30 31 32 |
# File 'lib/cocina_display/events/event.rb', line 27 def label return cocina["displayLabel"] if cocina["displayLabel"].present? return dates.map(&:label).first if date_only? type&.capitalize || date_types.first&.capitalize || "Event" end |
#locations ⇒ Array<CocinaDisplay::Events::Location>
All locations associated with this event.
98 99 100 101 102 |
# File 'lib/cocina_display/events/event.rb', line 98 def locations @locations ||= Array(cocina["location"]).map do |location| CocinaDisplay::Events::Location.new(location) end end |
#notes ⇒ Array<CocinaDisplay::Events::Note>
All notes associated with this event.
106 107 108 109 110 |
# File 'lib/cocina_display/events/event.rb', line 106 def notes @notes ||= Array(cocina["note"]).map do |note| CocinaDisplay::Events::Note.new(note) end end |
#to_s ⇒ String
String representation of the event using date and location.
115 116 117 |
# File 'lib/cocina_display/events/event.rb', line 115 def to_s Utils.compact_and_join([place_str, date_str], delimiter: ", ") end |
#type ⇒ String?
This can differ from the contained date types.
The declared type of the event, like “publication” or “creation”.
38 39 40 |
# File 'lib/cocina_display/events/event.rb', line 38 def type cocina["type"] end |
#types ⇒ Array<String>
Union of event’s type and its date types. Used for imprint detection and display decisions.
122 123 124 |
# File 'lib/cocina_display/events/event.rb', line 122 def types [type, *date_types].compact end |