Class: Aker::Factories::Container

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/aker/factories/container.rb

Overview

A Container is something that stores a sample. At this stage it is not defined. Must have a barcode

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params) ⇒ Container

Returns a new instance of Container.


19
20
21
22
23
# File 'app/aker/factories/container.rb', line 19

def initialize(params)
  params ||= {}
  @barcode = params[:barcode]
  @address = params[:address]
end

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address.


11
12
13
# File 'app/aker/factories/container.rb', line 11

def address
  @address
end

#barcodeObject (readonly)

Returns the value of attribute barcode.


11
12
13
# File 'app/aker/factories/container.rb', line 11

def barcode
  @barcode
end

#modelObject (readonly)

Returns the value of attribute model.


11
12
13
# File 'app/aker/factories/container.rb', line 11

def model
  @model
end

Class Method Details

.create(params) ⇒ Object


15
16
17
# File 'app/aker/factories/container.rb', line 15

def self.create(params)
  new(params).create
end

Instance Method Details

#a_well?Boolean

Returns:

  • (Boolean)

42
43
44
# File 'app/aker/factories/container.rb', line 42

def a_well?
  !Aker::Container.tube_address?(address)
end

#as_json(_options = {}) ⇒ Object


38
39
40
# File 'app/aker/factories/container.rb', line 38

def as_json(_options = {})
  model.as_json
end

#createObject


25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/aker/factories/container.rb', line 25

def create
  return unless valid?

  @model =
    Aker::Container.find_or_create_by(barcode: barcode, address: address) do |m|
      @labware = find_or_create_asset_by_aker_barcode!

      # Connects Aker container with asset. If is a plate, connects with the well, if is a tube, directly with
      # the tube
      m.update(asset: a_well? ? @labware.wells.located_at(address_for_ss).first : @labware)
    end
end