Class: PlateTemplateTask::SpreadsheetReader

Inherits:
Object
  • Object
show all
Defined in:
app/models/plate_template_task.rb

Overview

Class to extract the layout from an uploaded spreadsheet

Instance Method Summary collapse

Constructor Details

#initialize(csv_string, batch, plate_size) ⇒ SpreadsheetReader

Returns a new instance of SpreadsheetReader.


10
11
12
13
14
# File 'app/models/plate_template_task.rb', line 10

def initialize(csv_string, batch, plate_size)
  @csv_string = csv_string
  @requests = batch.requests.includes(asset: [:map, { plate: :barcodes }]).index_by(&:id)
  @plate_size = plate_size
end

Instance Method Details

#layoutObject

rubocop:todo Metrics/MethodLength


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/plate_template_task.rb', line 17

def layout # rubocop:todo Metrics/AbcSize
  barcodes = Set.new
  plates =
    mapped_plate_wells.each_value.map do |mapped_wells|
      Array.new(plate_size) do |i|
        request_id = mapped_wells[i]
        if request_id.present?
          asset = requests[request_id].asset
          barcodes << asset.plate.barcode_number
          [request_id, asset.plate.barcode_number, asset.display_name]
        else
          CherrypickTask::EMPTY_WELL
        end
      end
    end

  [plates, barcodes.to_a]
end