Class: Pooling

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

Overview

Used by PoolingsController to take multiple scanned Tube barcodes containing one or more aliquots and use them to generate a new MultiplexedLibraryTube

Defined Under Namespace

Classes: TagClashReport

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#barcode_printerObject

Returns the value of attribute barcode_printer.



9
10
11
# File 'app/models/pooling.rb', line 9

def barcode_printer
  @barcode_printer
end

#barcodesObject



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

def barcodes
  @barcodes || []
end

#countObject

Returns the value of attribute count.



9
10
11
# File 'app/models/pooling.rb', line 9

def count
  @count
end

#source_assetsObject



49
50
51
# File 'app/models/pooling.rb', line 49

def source_assets
  @source_assets ||= find_source_assets
end

#standard_mx_tubeObject

Returns the value of attribute standard_mx_tube.



9
10
11
# File 'app/models/pooling.rb', line 9

def standard_mx_tube
  @standard_mx_tube
end

#stock_mx_tubeObject

Returns the value of attribute stock_mx_tube.



9
10
11
# File 'app/models/pooling.rb', line 9

def stock_mx_tube
  @stock_mx_tube
end

#stock_mx_tube_requiredObject

Returns the value of attribute stock_mx_tube_required.



9
10
11
# File 'app/models/pooling.rb', line 9

def stock_mx_tube_required
  @stock_mx_tube_required
end

Instance Method Details

#each_transfer {|@stock_mx_tube, @standard_mx_tube| ... } ⇒ Object



42
43
44
45
46
47
# File 'app/models/pooling.rb', line 42

def each_transfer
  source_assets.each { |source_asset| yield source_asset, @stock_mx_tube || @standard_mx_tube }
  return unless stock_mx_tube_required?

  yield @stock_mx_tube, @standard_mx_tube
end

#executeObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/models/pooling.rb', line 16

def execute
  return false unless valid?

  if stock_mx_tube_required?
    @stock_mx_tube = Tube::Purpose.stock_mx_tube.create!(name: '(s)')
    @stock_mx_tube.parents = source_assets
  end

  @standard_mx_tube = Tube::Purpose.standard_mx_tube.create!
  @standard_mx_tube.parents = @stock_mx_tube ? [@stock_mx_tube] : source_assets
  transfer
  execute_print_job
  true
end

#messageObject



79
80
81
# File 'app/models/pooling.rb', line 79

def message
  @message ||= Hash.new('')
end


69
70
71
72
73
74
75
76
77
# File 'app/models/pooling.rb', line 69

def print_job
  @print_job ||=
    LabelPrinter::PrintJob.new(
      barcode_printer,
      LabelPrinter::Label::MultiplexedTube,
      assets: target_assets,
      count: count
    )
end

Returns:

  • (Boolean)


65
66
67
# File 'app/models/pooling.rb', line 65

def print_job_required?
  barcode_printer.present? && count.to_i.positive?
end

#stock_mx_tube_required?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'app/models/pooling.rb', line 61

def stock_mx_tube_required?
  stock_mx_tube_required.present?
end

#tag_clash_reportObject



83
84
85
# File 'app/models/pooling.rb', line 83

def tag_clash_report
  @tag_clash_report ||= Pooling::TagClashReport.new(self)
end

#target_assetsObject



53
54
55
# File 'app/models/pooling.rb', line 53

def target_assets
  @target_assets ||= [stock_mx_tube, standard_mx_tube].compact
end

#transferObject



31
32
33
34
35
36
37
38
39
40
# File 'app/models/pooling.rb', line 31

def transfer
  each_transfer do |source_asset, target_asset|
    # These transfers are not being performed to fulfil a specific request, so we explicitly
    # pass in a Request Null object. This will disable the attempt to detect an outer request.
    # We don't use nil as its *far* to easy to end up with nil by accident, so basing key behaviour
    # off it is risky.
    TransferRequest.create!(asset: source_asset, target_asset: target_asset, outer_request: Request::None.new)
  end
  message[:notice] = message[:notice] + success
end