Class: SequencescapeExcel::SpecialisedField::SangerTubeId

Inherits:
Object
  • Object
show all
Includes:
Base, ValueRequired
Defined in:
app/sequencescape_excel/sequencescape_excel/specialised_field/sanger_tube_id.rb

Overview

A required field if it is a tube manifest. Checked to ensure that it is the same as the sanger human barcode for sample, or is a valid foreign barcode. Updated if there is a valid foreign barcode.

Instance Attribute Summary collapse

Attributes included from Base

#sample_manifest_asset, #value

Instance Method Summary collapse

Methods included from Base

#link

Instance Attribute Details

#foreign_barcode_formatObject (readonly)

Returns the value of attribute foreign_barcode_format


14
15
16
# File 'app/sequencescape_excel/sequencescape_excel/specialised_field/sanger_tube_id.rb', line 14

def foreign_barcode_format
  @foreign_barcode_format
end

Instance Method Details

#update(attributes = {}) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/sequencescape_excel/sequencescape_excel/specialised_field/sanger_tube_id.rb', line 18

def update(attributes = {})
  return unless valid? && attributes[:aliquot].present? && foreign_barcode_format.present?

  # if this tube's list of barcodes already contains a foreign barcode with the same format then update the existing one
  foreign_barcode = attributes[:aliquot].receptacle.barcodes.find { |item| item[:format] == foreign_barcode_format.to_s }
  if foreign_barcode.present?
    if foreign_barcode.barcode != value
      foreign_barcode.update(barcode: value)
      attributes[:aliquot].sample.sample_manifest.update_barcodes if attributes[:aliquot].sample.sample_manifest.present?
    end
  else
    attributes[:aliquot].receptacle.labware.barcodes << Barcode.new(format: foreign_barcode_format, barcode: value)
    attributes[:aliquot].sample.sample_manifest.update_barcodes if attributes[:aliquot].sample.sample_manifest.present?
  end
end