Class: StockStamper

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/stock_stamper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = { overage: 1.2 }) ⇒ StockStamper

Returns a new instance of StockStamper


14
15
16
# File 'app/models/stock_stamper.rb', line 14

def initialize(attributes = { overage: 1.2 })
  super
end

Instance Attribute Details

#destination_plate_barcodeObject

Returns the value of attribute destination_plate_barcode


4
5
6
# File 'app/models/stock_stamper.rb', line 4

def destination_plate_barcode
  @destination_plate_barcode
end

#destination_plate_type_nameObject

Returns the value of attribute destination_plate_type_name


5
6
7
# File 'app/models/stock_stamper.rb', line 5

def destination_plate_type_name
  @destination_plate_type_name
end

#file_contentObject

Returns the value of attribute file_content


4
5
6
# File 'app/models/stock_stamper.rb', line 4

def file_content
  @file_content
end

#overageObject

Returns the value of attribute overage


4
5
6
# File 'app/models/stock_stamper.rb', line 4

def overage
  @overage
end

#plateObject (readonly)

Returns the value of attribute plate


5
6
7
# File 'app/models/stock_stamper.rb', line 5

def plate
  @plate
end

#plate_typeObject (readonly)

Returns the value of attribute plate_type


5
6
7
# File 'app/models/stock_stamper.rb', line 5

def plate_type
  @plate_type
end

#source_plate_barcodeObject

Returns the value of attribute source_plate_barcode


4
5
6
# File 'app/models/stock_stamper.rb', line 4

def source_plate_barcode
  @source_plate_barcode
end

#source_plate_type_nameObject

Returns the value of attribute source_plate_type_name


4
5
6
# File 'app/models/stock_stamper.rb', line 4

def source_plate_type_name
  @source_plate_type_name
end

#userObject (readonly)

Returns the value of attribute user


5
6
7
# File 'app/models/stock_stamper.rb', line 5

def user
  @user
end

#user_barcodeObject

Returns the value of attribute user_barcode


4
5
6
# File 'app/models/stock_stamper.rb', line 4

def user_barcode
  @user_barcode
end

Instance Method Details

#create_asset_audit_eventObject


59
60
61
# File 'app/models/stock_stamper.rb', line 59

def create_asset_audit_event
  AssetAudit.create(asset_id: plate.id, key: 'stamping_of_stock', message: "Process 'Stamping of stock' performed", created_by: user.)
end

#executeObject


18
19
20
21
22
23
# File 'app/models/stock_stamper.rb', line 18

def execute
  generate_tecan_gwl_file_as_text
  create_asset_audit_event
  message[:error] = "Required volume exceeds the maximum well volume for well(s) #{wells_with_excess.join(', ')}. Maximum well volume #{plate_type.maximum_volume.to_f} will be used in tecan file" if wells_with_excess.present?
  message[:notice] = 'You can generate the TECAN file and print label now.'
end

#generate_tecan_dataObject


29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/stock_stamper.rb', line 29

def generate_tecan_data
  source_barcode = "#{plate.machine_barcode}_s"
  destination_barcode = "#{plate.machine_barcode}_d"
  data_object = {
    'user' => user.,
    'time' => Time.now,
    'source' => {
      source_barcode => { 'name' => source_plate_type_name.tr('_', "\s"), 'plate_size' => plate.size }
    },
    'destination' => {
      destination_barcode => {
        'name' => destination_plate_type_name.tr('_', "\s"),
        'plate_size' => plate.size,
        'mapping' => []
      }
    }
  }
  plate.wells.without_blank_samples.each do |well|
    next unless well.get_current_volume

    data_object['destination'][destination_barcode]['mapping'] << {
      'src_well' => [source_barcode, well.map.description],
      'dst_well' => well.map.description,
      'volume' => volume(well),
      'buffer_volume' => well.get_buffer_volume
    }
  end
  data_object
end

#generate_tecan_gwl_file_as_textObject


25
26
27
# File 'app/models/stock_stamper.rb', line 25

def generate_tecan_gwl_file_as_text
  @file_content = Sanger::Robots::Tecan::Generator.mapping(generate_tecan_data, 0)
end

#messageObject


63
64
65
# File 'app/models/stock_stamper.rb', line 63

def message
  @message ||= {}
end

#wells_with_excessObject


67
68
69
# File 'app/models/stock_stamper.rb', line 67

def wells_with_excess
  @wells_with_excess ||= []
end