Class: Plate::CreatorParameters

Inherits:
Object
  • Object
show all
Defined in:
app/models/plate/creator_parameters.rb

Instance Method Summary collapse

Constructor Details

#initialize(params_plate_creator) ⇒ CreatorParameters

Returns a new instance of CreatorParameters.



6
7
8
# File 'app/models/plate/creator_parameters.rb', line 6

def initialize(params_plate_creator)
  @params = params_plate_creator
end

Instance Method Details

#params_has_dilution_factor?(params) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/plate/creator_parameters.rb', line 24

def params_has_dilution_factor?(params)
  !params[:dilution_factor].nil? && !params[:dilution_factor].to_s.empty?
end

#plate_dilution_factor(plate) ⇒ Object



16
17
18
19
20
21
22
# File 'app/models/plate/creator_parameters.rb', line 16

def plate_dilution_factor(plate)
  return plate.dilution_factor unless plate.nil?

  # If nobody specify any dilution factor (not even the PlateCreator), I can't assume any
  # default dilution factor. We'll fall back to database default value (if it has one)
  nil
end

#plate_parameters(_plate, parent_plate = nil) ⇒ Object

rubocop:todo Metrics/MethodLength



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/models/plate/creator_parameters.rb', line 28

def plate_parameters(_plate, parent_plate = nil) # rubocop:todo Metrics/MethodLength
  params = @params.clone

  parent_dilution_factor = plate_dilution_factor(parent_plate)
  if params_has_dilution_factor?(params)
    # The dilution factor of the parent is propagated to the children taking the parent's dilution
    # as basis.
    unless parent_dilution_factor.nil?
      params[:dilution_factor] = (params[:dilution_factor].to_d * parent_dilution_factor)
    end
  else
    # If not specified, I'll inherit the value of the source plate (if it has one)
    params[:dilution_factor] = parent_dilution_factor
  end

  # If I don't have a dilution factor yet, I'll let the value fall back to database default
  params.delete(:dilution_factor) if params[:dilution_factor].nil?

  # Remove any symbol not valid for plate creation (just dilution factor at now)
  params.delete_if { |k, _v| k.to_sym != :dilution_factor }
end

#set_plate_parameters(plate, parent_plate = nil) ⇒ Object



10
11
12
13
14
# File 'app/models/plate/creator_parameters.rb', line 10

def set_plate_parameters(plate, parent_plate = nil)
  # All the creation parameters are applied as String values into the ActiveRecord. Maybe in
  # future this will need to be reviewed in case Ruby conversion from strings is not appropriate
  plate.update!(plate_parameters(plate, parent_plate)) unless @params.nil?
end