Class: Robot

Inherits:
ApplicationRecord show all
Includes:
ModelExtensions::Robot, Uuid::Uuidable
Defined in:
app/models/robot.rb

Overview

rubocop:todo Style/Documentation

Defined Under Namespace

Modules: Generator, Verification Classes: PickData

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Uuid::Uuidable

included, #unsaved_uuid!, #uuid

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

.find_by_barcode(code) ⇒ Object Also known as: find_from_barcode


84
85
86
87
# File 'app/models/robot.rb', line 84

def find_by_barcode(code)
  human_robot_barcode = Barcode.number_to_human(code)
  Robot.find_by(barcode: human_robot_barcode) || Robot.find_by(id: human_robot_barcode)
end

.prefixObject


80
81
82
# File 'app/models/robot.rb', line 80

def prefix
  'RB'
end

.valid_barcode?(code) ⇒ Boolean

Returns:

  • (Boolean)

89
90
91
92
93
94
95
# File 'app/models/robot.rb', line 89

def valid_barcode?(code)
  Barcode.barcode_to_human!(code, prefix)
  find_from_barcode(code) # an exception is raise if not found
  true
rescue StandardError
  false
end

Instance Method Details

#all_picks(batch) ⇒ Object


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

def all_picks(batch)
  verification_behaviour.all_picks(batch, max_beds)
end

#generation_behaviourObject


52
53
54
55
56
57
58
59
# File 'app/models/robot.rb', line 52

def generation_behaviour
  {
    'Hamilton' => Robot::Generator::Hamilton,
    'Tecan' => Robot::Generator::Tecan,
    'TecanV2' => Robot::Generator::TecanV2,
    'Beckman' => Robot::Generator::Beckman
  }.fetch(generation_behaviour_property&.value, Robot::Generator::Tecan)
end

#generator(batch:, plate_barcode:, pick_number:) ⇒ Object


61
62
63
64
65
# File 'app/models/robot.rb', line 61

def generator(batch:, plate_barcode:, pick_number:)
  picking_data = Robot::PickData.new(batch, max_beds: max_beds).picking_data_hash(plate_barcode)[pick_number]
  layout = verification_behaviour.layout_data_object(picking_data)
  generation_behaviour.new(batch: batch, plate_barcode: plate_barcode, picking_data: picking_data, layout: layout)
end

#max_bedsObject


44
45
46
# File 'app/models/robot.rb', line 44

def max_beds
  max_plates_property.try(:value).to_i
end

#pick_number_to_expected_layout(batch, plate_barcode) ⇒ Object


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

def pick_number_to_expected_layout(batch, plate_barcode)
  verification_behaviour.pick_number_to_expected_layout(batch, plate_barcode, max_beds)
end

#pick_numbers(batch, plate_barcode) ⇒ Array<String>

Note:

Added as I refactor the batches/_assets.html.erb page. Currently just wraps pick_number_to_expected_layout and as a result performs a lot of unnecessary work.

Returns an array of all pick numbers associated with the corresponding batch and plate_barcode

Parameters:

  • batch (Batch)

    The Batch to get pick numbers for

  • plate_barcode (String)

    The barcode of the destination plate

Returns:

  • (Array<String>)

    Array of pick numbers associated with the batch/plate


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

def pick_numbers(batch, plate_barcode)
  verification_behaviour.pick_numbers(batch, plate_barcode, max_beds)
end

#verification_behaviourObject


48
49
50
# File 'app/models/robot.rb', line 48

def verification_behaviour
  @verification_behaviour ||= verification_class.new
end