Class: Robots::Bed::Base

Inherits:
Object
  • Object
show all
Includes:
Form
Defined in:
app/models/robots/bed/base.rb

Overview

A bed is a barcoded area of a robot that can receive a labware.

Direct Known Subclasses

PlateToTubeRacksBed, Pooling, Splitting

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#barcodesObject



62
63
64
# File 'app/models/robots/bed/base.rb', line 62

def barcodes
  @barcodes ||= []
end

#childObject

Our robot has beds/rack-spaces



9
10
11
# File 'app/models/robots/bed/base.rb', line 9

def child
  @child
end

#labelObject

Our robot has beds/rack-spaces



9
10
11
# File 'app/models/robots/bed/base.rb', line 9

def label
  @label
end

#parentsObject

Our robot has beds/rack-spaces



9
10
11
# File 'app/models/robots/bed/base.rb', line 9

def parents
  @parents
end

#purposeObject

Our robot has beds/rack-spaces



9
10
11
# File 'app/models/robots/bed/base.rb', line 9

def purpose
  @purpose
end

#robotObject

Our robot has beds/rack-spaces



9
10
11
# File 'app/models/robots/bed/base.rb', line 9

def robot
  @robot
end

#shared_parentObject

Our robot has beds/rack-spaces



9
10
11
# File 'app/models/robots/bed/base.rb', line 9

def shared_parent
  @shared_parent
end

#statesObject

Our robot has beds/rack-spaces



9
10
11
# File 'app/models/robots/bed/base.rb', line 9

def states
  @states
end

#target_stateObject

Our robot has beds/rack-spaces



9
10
11
# File 'app/models/robots/bed/base.rb', line 9

def target_state
  @target_state
end

Instance Method Details

#barcodeObject



66
67
68
# File 'app/models/robots/bed/base.rb', line 66

def barcode
  barcodes.first
end

#error_messagesObject



33
34
35
# File 'app/models/robots/bed/base.rb', line 33

def error_messages
  errors.full_messages.join(' ')
end

#find_all_labwareObject

overriden in sub-classes of bed to customise what class is used and what is included



71
72
73
# File 'app/models/robots/bed/base.rb', line 71

def find_all_labware
  Sequencescape::Api::V2::Labware.find_all({ barcode: @barcodes }, includes: %i[purpose parents])
end

#formatted_messageObject



96
97
98
# File 'app/models/robots/bed/base.rb', line 96

def formatted_message
  "#{label} - #{errors.full_messages.join('; ')}"
end

#labwareObject



82
83
84
# File 'app/models/robots/bed/base.rb', line 82

def labware
  @labware&.first
end

#load(barcodes) ⇒ Object



75
76
77
78
79
80
# File 'app/models/robots/bed/base.rb', line 75

def load(barcodes)
  # Ensure we always deal with an array, and any accidental duplicate scans are squashed out
  @barcodes = Array(barcodes).map(&:strip).uniq.compact_blank

  @labware = @barcodes.present? ? find_all_labware : []
end

#parentObject



41
42
43
# File 'app/models/robots/bed/base.rb', line 41

def parent
  (@parents || []).first
end

#parent=(parent_bed) ⇒ Object



37
38
39
# File 'app/models/robots/bed/base.rb', line 37

def parent=(parent_bed)
  @parents = [parent_bed]
end

#parent_labwareObject



86
87
88
89
90
91
92
93
94
# File 'app/models/robots/bed/base.rb', line 86

def parent_labware
  return [] if labware.nil?

  parents = labware.parents
  return parents if parents.present?

  error("Labware #{labware.human_barcode} doesn't seem to have any parents, and yet at least one was expected.")
  []
end

#persisted?Boolean Originally defined in module Form

Returns:

  • (Boolean)

#purpose_labelsObject



58
59
60
# File 'app/models/robots/bed/base.rb', line 58

def purpose_labels
  Array(purpose).to_sentence(two_words_connector: ' or ', last_word_connector: ' or ')
end

#recognised?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/models/robots/bed/base.rb', line 29

def recognised?
  true
end

#transitionObject

rubocop:todo Metrics/AbcSize



49
50
51
52
53
54
55
56
# File 'app/models/robots/bed/base.rb', line 49

def transition # rubocop:todo Metrics/AbcSize
  return if target_state.nil? || labware.nil? # We have nothing to do

  StateChangers
    .lookup_for(labware.purpose.uuid)
    .new(api, labware.uuid, user_uuid)
    .move_to!(target_state, "Robot #{robot.name} started")
end

#transitions?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/robots/bed/base.rb', line 45

def transitions?
  target_state.present?
end