Class: Tube

Inherits:
Object
  • Object
show all
Extended by:
QcFile::Associations
Includes:
Api::Messages::QcResultIO::TubeExtensions, Asset::Ownership::Unowned, AssetRefactor::Labware::Methods, Barcode::Barcodeable, ModelExtensions::Tube, SingleReceptacleLabware, Tag::Associations, Transfer::Associations, Transfer::State::TubeState
Defined in:
app/models/tube.rb

Overview

A Tube is a piece of Labware

Defined Under Namespace

Modules: AttributeUpdater Classes: MixedSubmissionMx, Purpose, StandardMx, StockMx

Instance Attribute Summary

Attributes included from AssetRefactor::Labware::Methods

#storage_location_service

Class Method Summary collapse

Instance Method Summary collapse

Methods included from QcFile::Associations

has_qc_files

Methods included from AssetRefactor::Labware::Methods

#labware, #labwhere_location, #scanned_in_date, #storage_location

Methods included from Transfer::State::TubeState

included

Methods included from Transfer::Associations

included

Methods included from Asset::Ownership::Unowned

#change_owner_to

Methods included from Tag::Associations

#untag!

Methods included from Barcode::Barcodeable

#aker_barcode, #aker_barcode=, #any_barcode_matching?, #barcode_format, #barcode_number, #cgap_barcode, #cgap_barcode=, #external_barcode, #external_barcode=, #external_identifier, #fluidigm_barcode, #fluidigm_barcode=, #generate_barcode, included, #infinium_barcode, #infinium_barcode=, #prefix, #primary_barcode, #printable_target, #sanger_barcode

Class Method Details

.create_with_barcode!(*args, &block) ⇒ Object


98
99
100
101
102
103
104
105
106
107
108
109
# File 'app/models/tube.rb', line 98

def self.create_with_barcode!(*args, &block)
  attributes = args.extract_options!
  barcode    = args.first || attributes.delete(:barcode)
  prefix     = attributes.delete(:barcode_prefix)&.prefix || default_prefix
  if barcode.present?
    human = SBCF::SangerBarcode.new(prefix: prefix, number: barcode).human_barcode
    raise "Barcode: #{barcode} already used!" if Barcode.where(barcode: human).exists?
  end
  barcode ||= AssetBarcode.new_barcode
  primary_barcode = { prefix: prefix, number: barcode }
  create!(attributes.merge(sanger_barcode: primary_barcode), &block)
end

.delegate_to_purpose(*methods) ⇒ Object


71
72
73
74
75
# File 'app/models/tube.rb', line 71

def self.delegate_to_purpose(*methods)
  methods.each do |method|
    class_eval("def #{method}(*args, &block) ; purpose.#{method}(self, *args, &block) ; end")
  end
end

Instance Method Details

#after_comment_addition(comment) ⇒ Object


94
95
96
# File 'app/models/tube.rb', line 94

def after_comment_addition(comment)
  comments.add_comment_to_submissions(comment)
end

#ancestor_of_purpose(ancestor_purpose_id) ⇒ Object


59
60
61
62
63
# File 'app/models/tube.rb', line 59

def ancestor_of_purpose(ancestor_purpose_id)
  return self if plate_purpose_id == ancestor_purpose_id

  ancestors.order(created_at: :desc).find_by(plate_purpose_id: ancestor_purpose_id)
end

#barcode!Object


34
35
36
37
# File 'app/models/tube.rb', line 34

def barcode!
  self.sanger_barcode = { number: AssetBarcode.new_barcode, prefix: default_prefix } unless barcode_number
  save!
end

#commentsObject


41
42
43
# File 'app/models/tube.rb', line 41

def comments
  @comments ||= CommentsProxy::Tube.new(self)
end

#detailsObject


90
91
92
# File 'app/models/tube.rb', line 90

def details
  purpose.try(:name) || 'Tube'
end

#name_for_child_tubeObject


82
83
84
# File 'app/models/tube.rb', line 82

def name_for_child_tube
  name
end

#name_for_labelObject


65
66
67
# File 'app/models/tube.rb', line 65

def name_for_label
  primary_sample&.shorten_sanger_sample_id.presence || name
end

#pool_idObject


49
50
51
# File 'app/models/tube.rb', line 49

def pool_id
  submissions.ids.first
end

#sanger_barcode=(attributes) ⇒ Object


86
87
88
# File 'app/models/tube.rb', line 86

def sanger_barcode=(attributes)
  barcodes << Barcode.build_sanger_ean13(attributes)
end

#source_plateObject


53
54
55
56
57
# File 'app/models/tube.rb', line 53

def source_plate
  return nil if purpose.nil?

  @source_plate ||= purpose.source_plate(self)
end

#subject_typeObject


30
31
32
# File 'app/models/tube.rb', line 30

def subject_type
  'tube'
end

#submissionObject


45
46
47
# File 'app/models/tube.rb', line 45

def submission
  submissions.first
end