Class: CocinaDisplay::Events::Event
- Inherits:
-
Object
- Object
- CocinaDisplay::Events::Event
- 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
-
#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.
-
#initialize(cocina) ⇒ Event
constructor
Initialize the event with Cocina event data.
-
#locations ⇒ Array<CocinaDisplay::Events::Location>
All locations associated with this event.
-
#type ⇒ String?
The declared type of the event, like “publication” or “creation”.
Constructor Details
#initialize(cocina) ⇒ Event
Initialize the event with Cocina event data.
13 14 15 |
# File 'lib/cocina_display/events/event.rb', line 13 def initialize(cocina) @cocina = cocina end |
Instance Attribute Details
#cocina ⇒ Object (readonly)
Returns the value of attribute cocina.
9 10 11 |
# File 'lib/cocina_display/events/event.rb', line 9 def cocina @cocina end |
Instance Method Details
#contributors ⇒ Array<CocinaDisplay::Contributor>
All contributors associated with this event.
63 64 65 66 67 |
# File 'lib/cocina_display/events/event.rb', line 63 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.
29 30 31 |
# File 'lib/cocina_display/events/event.rb', line 29 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.
52 53 54 55 56 57 58 59 |
# File 'lib/cocina_display/events/event.rb', line 52 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.
43 44 45 |
# File 'lib/cocina_display/events/event.rb', line 43 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.
36 37 38 |
# File 'lib/cocina_display/events/event.rb', line 36 def has_type?(match_type) [type, *date_types].compact.include?(match_type) end |
#locations ⇒ Array<CocinaDisplay::Events::Location>
All locations associated with this event.
71 72 73 74 75 |
# File 'lib/cocina_display/events/event.rb', line 71 def locations @locations ||= Array(cocina["location"]).map do |location| CocinaDisplay::Events::Location.new(location) end end |
#type ⇒ String?
This can differ from the contained date types.
The declared type of the event, like “publication” or “creation”.
21 22 23 |
# File 'lib/cocina_display/events/event.rb', line 21 def type cocina["type"] end |