Class: Aker::Container

Inherits:
ApplicationRecord show all
Defined in:
app/models/aker/container.rb

Overview

Phisical container for the biomaterial

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Squishify

extended

Class Method Details

.tube_address?(address) ⇒ Boolean

Returns:

  • (Boolean)

52
53
54
# File 'app/models/aker/container.rb', line 52

def self.tube_address?(address)
  (address =~ /^\d/) || address.nil?
end

Instance Method Details

#a_well?Boolean

Returns:

  • (Boolean)

44
45
46
47
48
49
50
# File 'app/models/aker/container.rb', line 44

def a_well?
  if asset
    asset.is_a? Well
  else
    !self.class.tube_address?(address)
  end
end

#aliquots?Boolean

Returns:

  • (Boolean)

74
75
76
# File 'app/models/aker/container.rb', line 74

def aliquots?
  asset.aliquots.count.positive?
end

#amountObject


30
31
32
33
34
# File 'app/models/aker/container.rb', line 30

def amount
  return (volume.to_f * concentration.to_f).to_s if volume && concentration

  nil
end

#as_json(_options = {}) ⇒ Object


56
57
58
# File 'app/models/aker/container.rb', line 56

def as_json(_options = {})
  { barcode: barcode, address: address }.compact
end

#concentrationObject


22
23
24
25
26
27
28
# File 'app/models/aker/container.rb', line 22

def concentration
  value = asset.get_qc_result_value_for('concentration')
  return value if value
  return asset.concentration unless a_well?

  asset.well_attribute.concentration
end

#contains_sample?(sample) ⇒ Boolean

Returns:

  • (Boolean)

70
71
72
# File 'app/models/aker/container.rb', line 70

def contains_sample?(sample)
  asset.aliquots.where(sample: sample).count.positive?
end

#not_change_addressObject


40
41
42
# File 'app/models/aker/container.rb', line 40

def not_change_address
  errors.add(:address, 'Cannot modify address') if persisted? && address_changed?
end

#not_change_barcodeObject


36
37
38
# File 'app/models/aker/container.rb', line 36

def not_change_barcode
  errors.add(:barcode, 'Cannot modify barcode') if persisted? && barcode_changed?
end

#put_sample_in_container(sample, study) ⇒ Object


60
61
62
63
64
65
66
67
68
# File 'app/models/aker/container.rb', line 60

def put_sample_in_container(sample, study)
  save if asset.nil?
  sample.update(container: self)
  if !contains_sample?(sample) && aliquots?
    raise 'The contents of this plate are not up to date with aker job message'
  end

  asset.aliquots.create!(sample: sample, study: study) unless contains_sample?(sample)
end

#volumeObject


14
15
16
17
18
19
20
# File 'app/models/aker/container.rb', line 14

def volume
  value = asset.get_qc_result_value_for('volume')
  return value if value
  return asset.volume unless a_well?

  asset.well_attribute.current_volume
end