Class: SdrClient::RedesignedClient::StructuralGrouper

Inherits:
Object
  • Object
show all
Defined in:
lib/sdr_client/redesigned_client/structural_grouper.rb

Overview

Builds and constructs the structural metadata given upload responses (file IDs, file set grouping strategies, etc.)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(request_builder:, upload_responses:, grouping_strategy:, file_set_strategy: nil) ⇒ StructuralGrouper

Returns a new instance of StructuralGrouper.

Parameters:

  • request_biulder (RequestBuilder)

    a request builder instance

  • upload_responses (Array<DirectUploadResponse>)

    upload response instances

  • grouping_strategy (String)

    what strategy will be used to group files

  • file_set_strategy (String) (defaults to: nil)

    what strategy will be used to group file sets



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/sdr_client/redesigned_client/structural_grouper.rb', line 16

def initialize(request_builder:, upload_responses:, grouping_strategy:, file_set_strategy: nil) # rubocop:disable Metrics/MethodLength
  @request_builder = request_builder
  @upload_responses = upload_responses
  @grouping_strategy = if grouping_strategy == 'filename'
                         SdrClient::RedesignedClient::MatchingFileGroupingStrategy
                       else
                         SdrClient::RedesignedClient::SingleFileGroupingStrategy
                       end
  @file_set_strategy = if file_set_strategy == 'image'
                         SdrClient::RedesignedClient::ImageFileSetStrategy
                       else
                         SdrClient::RedesignedClient::FileTypeFileSetStrategy
                       end
end

Class Method Details

.groupObject



8
9
10
# File 'lib/sdr_client/redesigned_client/structural_grouper.rb', line 8

def self.group(...)
  new(...).group
end

Instance Method Details

#groupObject



31
32
33
34
35
# File 'lib/sdr_client/redesigned_client/structural_grouper.rb', line 31

def group
  request_builder
    .tap { |request| request.file_sets = build_filesets(uploads: upload_responses) }
    .to_cocina
end