Class: Plate::SampleTubeFactory

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
app/models/plate/sample_tube_factory.rb

Overview

Extracted from Plate Used to convert a plate to SampleTube

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.create_sample_tubes_asset_group_and_print_barcodes(plates, barcode_printer, study) ⇒ Object

rubocop:todo Metrics/MethodLength, Metrics/AbcSize



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/models/plate/sample_tube_factory.rb', line 24

def self.create_sample_tubes_asset_group_and_print_barcodes(plates, barcode_printer, study)
  return nil if plates.empty?

  plate_barcodes = plates.map(&:barcode_number)
  asset_group =
    AssetGroup.find_or_create_asset_group("#{plate_barcodes.join('-')} #{Time.current.to_fs(:sortable)} ", study)
  plates.each do |plate|
    factory = Plate::SampleTubeFactory.new(plate)
    next if factory.wells.empty?

    asset_group.assets << factory.create_sample_tubes_and_print_barcodes(barcode_printer).map(&:receptacle)
  end

  return nil if asset_group.assets.empty?

  asset_group.save!

  asset_group
end

Instance Method Details

#create_child_sample_tube(well) ⇒ Object



9
10
11
12
13
# File 'app/models/plate/sample_tube_factory.rb', line 9

def create_child_sample_tube(well)
  Tube::Purpose.standard_sample_tube.create!.tap do |sample_tube|
    sample_tube.receptacle.transfer_requests_as_target.create!(asset: well)
  end
end

#create_sample_tubesObject



5
6
7
# File 'app/models/plate/sample_tube_factory.rb', line 5

def create_sample_tubes
  wells.map { |well| create_child_sample_tube(well) }
end

#create_sample_tubes_and_print_barcodes(barcode_printer) ⇒ Object



15
16
17
18
19
20
21
# File 'app/models/plate/sample_tube_factory.rb', line 15

def create_sample_tubes_and_print_barcodes(barcode_printer)
  sample_tubes = create_sample_tubes
  print_job = LabelPrinter::PrintJob.new(barcode_printer.name, LabelPrinter::Label::PlateToTubes, sample_tubes:)
  print_job.execute

  sample_tubes
end