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


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

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

Instance Attribute Details

#addressObject (readonly)

Returns the value of attribute address


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

def address
  @address
end

#barcodeObject (readonly)

Returns the value of attribute barcode


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

def barcode
  @barcode
end

#modelObject (readonly)

Returns the value of attribute model


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

def model
  @model
end

Class Method Details

.create(params) ⇒ Object


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

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

Instance Method Details

#a_well?Boolean

Returns:

  • (Boolean)

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

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

#as_json(_options = {}) ⇒ Object


35
36
37
# File 'app/aker/factories/container.rb', line 35

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

#createObject


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

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