Class: CocinaDisplay::Events::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/cocina_display/events/event.rb

Overview

An event associated with an object, like publication.

Direct Known Subclasses

Imprint

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cocina) ⇒ Event

Initialize the event with Cocina event data.

Parameters:

  • cocina (Hash)

    Cocina structured data for a single event



9
10
11
# File 'lib/cocina_display/events/event.rb', line 9

def initialize(cocina)
  @cocina = cocina
end

Instance Attribute Details

#cocinaObject (readonly)

Returns the value of attribute cocina.



5
6
7
# File 'lib/cocina_display/events/event.rb', line 5

def cocina
  @cocina
end

Instance Method Details

#contributorsArray<CocinaDisplay::Contributor>

All contributors associated with this event.

Returns:

  • (Array<CocinaDisplay::Contributor>)


59
60
61
62
63
# File 'lib/cocina_display/events/event.rb', line 59

def contributors
  @contributors ||= Array(cocina["contributor"]).map do |contributor|
    CocinaDisplay::Contributors::Contributor.new(contributor)
  end
end

#date_typesArray<String>

Note:

This can differ from the top-level event type.

All types of dates associated with this event.



25
26
27
# File 'lib/cocina_display/events/event.rb', line 25

def date_types
  dates.map(&:type).uniq
end

#datesArray<CocinaDisplay::Dates::Date>

Note:

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.

Returns:



48
49
50
51
52
53
54
55
# File 'lib/cocina_display/events/event.rb', line 48

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.

Parameters:

  • match_types (Array<String>)

    The types to check against

Returns:

  • (Boolean)


39
40
41
# File 'lib/cocina_display/events/event.rb', line 39

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.

Parameters:

  • match_type (String)

    The type to check against

Returns:

  • (Boolean)


32
33
34
# File 'lib/cocina_display/events/event.rb', line 32

def has_type?(match_type)
  [type, *date_types].compact.include?(match_type)
end

#locationsArray<CocinaDisplay::Events::Location>

All locations associated with this event.



67
68
69
70
71
# File 'lib/cocina_display/events/event.rb', line 67

def locations
  @locations ||= Array(cocina["location"]).map do |location|
    CocinaDisplay::Events::Location.new(location)
  end
end

#notesArray<CocinaDisplay::Events::Note>

All notes associated with this event.

Returns:



75
76
77
78
79
# File 'lib/cocina_display/events/event.rb', line 75

def notes
  @notes ||= Array(cocina["note"]).map do |note|
    CocinaDisplay::Events::Note.new(note)
  end
end

#typeString?

Note:

This can differ from the contained date types.

The declared type of the event, like “publication” or “creation”.



17
18
19
# File 'lib/cocina_display/events/event.rb', line 17

def type
  cocina["type"]
end