Class: Heron::Factories::TubeRack

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model, Concerns::Contents, Concerns::CoordinatesSupport, Concerns::ForeignBarcodes, Concerns::Recipients, Concerns::RecipientsCoordinates
Defined in:
app/models/heron/factories/tube_rack.rb

Overview

Factory class to create Heron tube racks

Constant Summary

Constants included from Concerns::CoordinatesSupport

Concerns::CoordinatesSupport::LOCATION_REGEXP

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concerns::Contents

#_factories_for_location, #add_aliquots_into_location, #add_aliquots_into_locations, #contents, included, #label_for_error_message, #params_for_contents, #study_uuid

Methods included from Concerns::Recipients

#check_recipients, included, #params_for_recipient, #recipients

Methods included from Concerns::RecipientsCoordinates

#check_recipient_coordinates, included

Methods included from Concerns::ForeignBarcodes

#barcode_format, #check_barcode_format, #check_foreign_barcode_unique, included

Methods included from Concerns::CoordinatesSupport

#coordinate_valid?, #unpad_coordinate

Constructor Details

#initialize(params) ⇒ TubeRack

Returns a new instance of TubeRack.



19
20
21
# File 'app/models/heron/factories/tube_rack.rb', line 19

def initialize(params)
  @params = params
end

Instance Attribute Details

#sample_tubesObject

Returns the value of attribute sample_tubes.



15
16
17
# File 'app/models/heron/factories/tube_rack.rb', line 15

def sample_tubes
  @sample_tubes
end

#tube_rackObject

Returns the value of attribute tube_rack.



15
16
17
# File 'app/models/heron/factories/tube_rack.rb', line 15

def tube_rack
  @tube_rack
end

Instance Method Details

#barcodeObject



35
36
37
# File 'app/models/heron/factories/tube_rack.rb', line 35

def barcode
  @params[:barcode]
end

#content_factoryObject



31
32
33
# File 'app/models/heron/factories/tube_rack.rb', line 31

def content_factory
  ::Heron::Factories::Sample
end

#purposeObject



45
46
47
# File 'app/models/heron/factories/tube_rack.rb', line 45

def purpose
  @purpose ||= ::TubeRack::Purpose.with_uuid(purpose_uuid).first
end

#purpose_uuidObject



41
42
43
# File 'app/models/heron/factories/tube_rack.rb', line 41

def purpose_uuid
  @params[:purpose_uuid]
end

#recipient_factoryObject



27
28
29
# File 'app/models/heron/factories/tube_rack.rb', line 27

def recipient_factory
  ::Heron::Factories::Tube
end

#recipients_keyObject



23
24
25
# File 'app/models/heron/factories/tube_rack.rb', line 23

def recipients_key
  :tubes
end

#sample_study_namesObject



65
66
67
68
69
70
71
72
73
74
75
76
# File 'app/models/heron/factories/tube_rack.rb', line 65

def sample_study_names
  return unless @tube_rack

  @tube_rack
    .tubes
    .each_with_object([]) do |tube, study_names|
      next if tube.aliquots.first.blank?

      study_names << tube.aliquots.first.study.name if tube.aliquots.first.study.present?
    end
    .uniq
end

#saveObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'app/models/heron/factories/tube_rack.rb', line 49

def save
  return false unless valid?

  ActiveRecord::Base.transaction do
    @tube_rack = ::TubeRack.create!(size:, purpose:)

    Barcode.create!(labware: tube_rack, barcode: barcode, format: barcode_format)

    create_recipients!
    create_contents!

    ::TubeRackStatus.create!(barcode: barcode, status: :created, labware: @tube_rack)
  end
  true
end