Class: DorIndexing::Builders::GeographicBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/dor_indexing/builders/geographic_builder.rb

Overview

Builds the geographic fields for a solr document

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(subjects) ⇒ GeographicBuilder

Returns a new instance of GeographicBuilder.



13
14
15
# File 'lib/dor_indexing/builders/geographic_builder.rb', line 13

def initialize(subjects)
  @subjects = Array(subjects)
end

Class Method Details

.build(subjects) ⇒ Array<String>

Returns the geographic values for Solr.

Parameters:

  • subjects (Array<Cocina::Models::Subject>)

Returns:

  • (Array<String>)

    the geographic values for Solr



9
10
11
# File 'lib/dor_indexing/builders/geographic_builder.rb', line 9

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

Instance Method Details

#buildObject



17
18
19
# File 'lib/dor_indexing/builders/geographic_builder.rb', line 17

def build
  extract_place_from_subjects(subjects)
end

#extract_place_from_subjects(local_subjects) ⇒ Object

rubocop:disable Metrics/AbcSize



22
23
24
25
26
27
28
29
30
31
# File 'lib/dor_indexing/builders/geographic_builder.rb', line 22

def extract_place_from_subjects(local_subjects)
  (
    build_place_nodes(local_subjects.select { |node| node.type == 'place' }) +
    local_subjects.reject(&:type).flat_map do |subject|
      next extract_place_from_subjects(subject.parallelValue) if subject.parallelValue.present?

      build_place_nodes(Array(subject.structuredValue).select { |node| node.type == 'place' })
    end
  ).uniq
end