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



13
14
15
# File 'lib/cocina_display/events/event.rb', line 13

def initialize(cocina)
  @cocina = cocina
end

Instance Attribute Details

#cocinaObject (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

#contributorsArray<CocinaDisplay::Contributor>

All contributors associated with this event.

Returns:

  • (Array<CocinaDisplay::Contributor>)


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_typesArray<String>

Note:

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

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



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.

Parameters:

  • match_types (Array<String>)

    The types to check against

Returns:

  • (Boolean)


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.

Parameters:

  • match_type (String)

    The type to check against

Returns:

  • (Boolean)


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

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

#typeString?

Note:

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