Class: DorIndexing::Selectors::EventSelector

Inherits:
Object
  • Object
show all
Defined in:
lib/dor_indexing/selectors/event_selector.rb

Overview

Selects the best event to use for indexing

Class Method Summary collapse

Class Method Details

.date_status_primary(date) ⇒ Boolean

Returns true if date.status == primary.

Parameters:

  • a (Cocina::Models::DescriptiveValue)

    date object from an event

Returns:

  • (Boolean)

    true if date.status == primary



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/dor_indexing/selectors/event_selector.rb', line 19

def self.date_status_primary(date)
  structured_primary = Array(date.structuredValue).find do |structured_date|
    structured_date.status == 'primary'
  end

  parallel_value_primary = Array(date.parallelValue).find do |parallel_value|
    parallel_value.status == 'primary'
  end

  date.status == 'primary' || structured_primary || parallel_value_primary
end

.select(events, desired_date_type) ⇒ Cocina::Models::Event?

Returns event best matching selected.

Parameters:

  • events (Array<Cocina::Models::Event>)
  • desired_date_type (String)

    a string to match the date.type in a Cocina::Models::Event

Returns:

  • (Cocina::Models::Event, nil)

    event best matching selected



10
11
12
13
14
15
# File 'lib/dor_indexing/selectors/event_selector.rb', line 10

def self.select(events, desired_date_type)
  date_type_matches_and_primary(events, desired_date_type) ||
    date_and_event_type_match(events, desired_date_type) ||
    event_type_matches_but_no_date_type(events, desired_date_type) ||
    event_has_date_type(events, desired_date_type)
end