Class: DorIndexing::Selectors::PubYearSelector

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

Overview

Finds the pub date to index from events

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(events) ⇒ PubYearSelector

Returns a new instance of PubYearSelector.



13
14
15
# File 'lib/dor_indexing/selectors/pub_year_selector.rb', line 13

def initialize(events)
  @events = events
end

Class Method Details

.build(events) ⇒ String

Returns the year value for Solr.

Parameters:

  • events (Array<Cocina::Models::Events>)

Returns:

  • (String)

    the year value for Solr



9
10
11
# File 'lib/dor_indexing/selectors/pub_year_selector.rb', line 9

def self.build(events)
  new(events).build
end

Instance Method Details

#buildObject



17
18
19
20
# File 'lib/dor_indexing/selectors/pub_year_selector.rb', line 17

def build
  date = find_date
  ParseDate.earliest_year(date).to_s if date.present?
end

#find_dateObject

rubocop:disable Metrics/PerceivedComplexity rubocop:disable Metrics/CyclomaticComplexity



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/dor_indexing/selectors/pub_year_selector.rb', line 24

def find_date
  primary_date(events) ||
    EventDateBuilder.build(production_event, 'production') ||
    EventDateBuilder.build(publication_event, 'publication') ||
    EventDateBuilder.build(capture_event, 'capture') ||
    EventDateBuilder.build(copyright_event, 'copyright') ||
    creation_date ||
    first_date ||
    structured_dates(events) ||
    find_date_in_parallel_events
end