Class: Plate::CreatorParameters
- Inherits:
-
Object
- Object
- Plate::CreatorParameters
- Defined in:
- app/models/plate/creator_parameters.rb
Overview
rubocop:todo Style/Documentation
Instance Method Summary collapse
-
#initialize(params_plate_creator) ⇒ CreatorParameters
constructor
A new instance of CreatorParameters.
- #params_has_dilution_factor?(params) ⇒ Boolean
- #plate_dilution_factor(plate) ⇒ Object
- #plate_parameters(_plate, parent_plate = nil) ⇒ Object
- #set_plate_parameters(plate, parent_plate = nil) ⇒ Object
Constructor Details
#initialize(params_plate_creator) ⇒ CreatorParameters
Returns a new instance of CreatorParameters.
5 6 7 |
# File 'app/models/plate/creator_parameters.rb', line 5 def initialize(params_plate_creator) @params = params_plate_creator end |
Instance Method Details
#params_has_dilution_factor?(params) ⇒ Boolean
23 24 25 |
# File 'app/models/plate/creator_parameters.rb', line 23 def params_has_dilution_factor?(params) (!params[:dilution_factor].nil?) && (!params[:dilution_factor].to_s.empty?) end |
#plate_dilution_factor(plate) ⇒ Object
15 16 17 18 19 20 21 |
# File 'app/models/plate/creator_parameters.rb', line 15 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
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/plate/creator_parameters.rb', line 27 def plate_parameters(_plate, parent_plate = nil) 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
9 10 11 12 13 |
# File 'app/models/plate/creator_parameters.rb', line 9 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 |