Class: Spotlight::BulkUpdatesCsvTemplateService

Inherits:
Object
  • Object
show all
Defined in:
app/services/spotlight/bulk_updates_csv_template_service.rb

Overview

A service to generate a CSV template suitable for re-uploading for bulk updates

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exhibit:) ⇒ BulkUpdatesCsvTemplateService

Returns a new instance of BulkUpdatesCsvTemplateService.



10
11
12
# File 'app/services/spotlight/bulk_updates_csv_template_service.rb', line 10

def initialize(exhibit:)
  @exhibit = exhibit
end

Instance Attribute Details

#exhibitObject (readonly)

Returns the value of attribute exhibit.



8
9
10
# File 'app/services/spotlight/bulk_updates_csv_template_service.rb', line 8

def exhibit
  @exhibit
end

Instance Method Details

#template(view_context:, title: true, tags: true, visibility: true) {|::CSV.generate_line(csv_headers(title: title, tags: tags, visibility: visibility))| ... } ⇒ Object

Yields:

  • (::CSV.generate_line(csv_headers(title: title, tags: tags, visibility: visibility)))


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/services/spotlight/bulk_updates_csv_template_service.rb', line 14

def template(view_context:, title: true, tags: true, visibility: true)
  return to_enum(:template, view_context: view_context, title: title, tags: tags, visibility: visibility) unless block_given?

  yield ::CSV.generate_line(csv_headers(title: title, tags: tags, visibility: visibility))
  each_document do |document|
    sidecar = document.sidecar(exhibit)
    yield ::CSV.generate_line([
      document.id,
      (title_column(view_context, document) if title),
      (visibility_column(sidecar) if visibility),
      (tags_column(sidecar) if tags)
    ].flatten.compact)
  end
end