Class: Robots::TubeRackWrapper
- Inherits:
-
Object
- Object
- Robots::TubeRackWrapper
- 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
-
#barcode ⇒ Object
Returns the value of attribute barcode.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#tubes ⇒ Object
Returns the value of attribute tubes.
Instance Method Summary collapse
-
#human_barcode ⇒ String
Returns the human readable barcode of the tube rack.
-
#initialize(barcode, parent, tubes: []) ⇒ TubeRackWrapper
constructor
Initializes a new instance of the class.
-
#last_tube ⇒ Tube
Returns the last tube on the tube rack.
-
#push_tube(tube) ⇒ Void
Appends a tube to the tube rack or replaces an existing tube.
Constructor Details
#initialize(barcode, parent, tubes: []) ⇒ TubeRackWrapper
Initializes a new instance of the class.
17 18 19 20 21 22 23 24 25 26 |
# File 'app/models/robots/tube_rack_wrapper.rb', line 17 def initialize(, parent, tubes: []) @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
#barcode ⇒ Object
Returns the value of attribute barcode.
8 9 10 |
# File 'app/models/robots/tube_rack_wrapper.rb', line 8 def @barcode end |
#parent ⇒ Object
Returns the value of attribute parent.
8 9 10 |
# File 'app/models/robots/tube_rack_wrapper.rb', line 8 def parent @parent end |
#tubes ⇒ Object
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_barcode ⇒ String
Returns the human readable barcode of the tube rack.
57 58 59 |
# File 'app/models/robots/tube_rack_wrapper.rb', line 57 def .human end |
#last_tube ⇒ Tube
Returns the last tube on the tube rack. This method is used for delegating certain methods to make it behave like a labware object.
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.
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 |