Class: LabEvent

Inherits:
ApplicationRecord show all
Includes:
ActsAsDescriptable
Defined in:
app/models/lab_event.rb

Constant Summary collapse

CHIP_BARCODE_STEPS =
['Cluster generation', 'Add flowcell chip barcode', 'Loading'].freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from ActsAsDescriptable

#add_descriptor, #descriptor_hash, #descriptor_value, #descriptors, included

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Warren::BroadcastMessages

#broadcast, included, #queue_associated_for_broadcast, #queue_for_broadcast, #warren

Class Method Details

.find_batch_id_by_barcode(barcode) ⇒ Object


31
32
33
34
# File 'app/models/lab_event.rb', line 31

def self.find_batch_id_by_barcode(barcode)
  batch_ids = with_flowcell_barcode(barcode).distinct.pluck(:batch_id)
  batch_ids.first if batch_ids.one?
end

Instance Method Details

#add_new_descriptor(name, value) ⇒ Object


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

def add_new_descriptor(name, value)
  add_descriptor Descriptor.new(name: name, value: value)
end

#descriptor_value_for(name) ⇒ Object


36
37
38
39
40
41
42
43
# File 'app/models/lab_event.rb', line 36

def descriptor_value_for(name)
  descriptors.each do |desc|
    if desc.name.casecmp(name.to_s).zero?
      return desc.value
    end
  end
  nil
end

#generate_broadcast_eventObject


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

def generate_broadcast_event
  BroadcastEvent::LabEvent.create!(seed: self, user: user)
end

#unescape_for_descriptorsObject


25
26
27
28
29
# File 'app/models/lab_event.rb', line 25

def unescape_for_descriptors
  self[:descriptors] = (self[:descriptors] || {}).to_h.each_with_object({}) do |(key, value), hash|
    hash[CGI.unescape(key)] = value
  end
end