Class: Robots::TubeRackWrapper

Inherits:
Object
  • Object
show all
Defined in:
app/models/robots/tube_rack_wrapper.rb

Overview

This wrapper class is for tube racks that are not actual recorded labware. The instance acts as a labware wrapper and provides access to the tubes. Labware methods are delegated to the last tube on the tube rack.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(barcode, parent, tubes: []) ⇒ TubeRackWrapper

Initializes a new instance of the class.

Parameters:

  • barcode (LabwareBarcode)

    the barcode object of the tube rack

  • parent (Plate)

    the parent plate

  • tubes (Array<Tube>) (defaults to: [])

    the tubes on the tube rack



17
18
19
20
21
22
23
24
25
26
# File 'app/models/robots/tube_rack_wrapper.rb', line 17

def initialize(barcode, parent, tubes: [])
  @barcode = barcode
  @parent = parent
  @tubes = []

  # Keep track of tube positions, tube coordinate on rack => index in
  # @tubes array, e.g. 'C1' => 0 .
  @tube_positions = {}
  tubes.each { |tube| push_tube(tube) } # Eliminate duplicate tubes by position
end

Instance Attribute Details

#barcodeObject

Returns the value of attribute barcode.



8
9
10
# File 'app/models/robots/tube_rack_wrapper.rb', line 8

def barcode
  @barcode
end

#parentObject

Returns the value of attribute parent.



8
9
10
# File 'app/models/robots/tube_rack_wrapper.rb', line 8

def parent
  @parent
end

#tubesObject

Returns the value of attribute tubes.



8
9
10
# File 'app/models/robots/tube_rack_wrapper.rb', line 8

def tubes
  @tubes
end

Instance Method Details

#human_barcodeString

Returns the human readable barcode of the tube rack.

Returns:

  • (String)

    the human readable barcode



57
58
59
# File 'app/models/robots/tube_rack_wrapper.rb', line 57

def human_barcode
  barcode.human
end

#last_tubeTube

Returns the last tube on the tube rack. This method is used for delegating certain methods to make it behave like a labware object.

Returns:

  • (Tube)

    the last tube



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

def last_tube
  @tubes.last
end

#push_tube(tube) ⇒ Void

Appends a tube to the tube rack or replaces an existing tube. If there is an existing tube with the same position, the tube with the latest creation date is kept.

Parameters:

  • tube (Tube)

    the tube to be added

Returns:

  • (Void)


43
44
45
46
47
48
49
50
51
# File 'app/models/robots/tube_rack_wrapper.rb', line 43

def push_tube(tube)
  index = @tube_positions[tube_rack_position(tube)]
  if index.present?
    @tubes[index] = tube if tube.created_at >= @tubes[index].created_at
  else
    @tubes.push(tube)
    @tube_positions[tube_rack_position(tube)] = @tubes.length - 1
  end
end