Class: Parsers::DilutionParser

Inherits:
Object
  • Object
show all
Defined in:
app/models/parsers/dilution_parser.rb

Overview

A dilution parser wraps other parsers and passes the relevant information on to the parent plate at the provided dilution factor.

Constant Summary collapse

UNSCALED =

Parameters which get passed on unchanged

['RIN'].freeze
SCALED =

Parameters which get multiplied by the scale factor

%w[concentration molarity].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(original_parser, scale_factor) ⇒ DilutionParser

Create a parse to pass to parent plates

Parameters:

  • original_parser (#each_well_and_parameters, #assay_type, #assay_version)

    The original parser to scale

  • scale_factor (Numeric)

    The scale factor by which to multiply concentrations



23
24
25
26
# File 'app/models/parsers/dilution_parser.rb', line 23

def initialize(original_parser, scale_factor)
  @original_parser = original_parser
  @scale_factor = scale_factor
end

Instance Attribute Details

#original_parserObject (readonly)

Other parameters (eg. volume) will not propagate



15
16
17
# File 'app/models/parsers/dilution_parser.rb', line 15

def original_parser
  @original_parser
end

#scale_factorObject (readonly)

Other parameters (eg. volume) will not propagate



15
16
17
# File 'app/models/parsers/dilution_parser.rb', line 15

def scale_factor
  @scale_factor
end

Instance Method Details

#assay_typeString

The assay type, appending ‘from -dilution’ to distinguish from direct measurement

Returns:

  • (String)

    The name of the assay



32
33
34
# File 'app/models/parsers/dilution_parser.rb', line 32

def assay_type
  "#{original_parser.assay_type} from dilution"
end

#each_well_and_parameters {|String, Hash| ... } ⇒ Object

Yield each well and the scaled attributes for each

Yields:

  • (String, Hash)

    Well name and a hash of attributes and their values



40
41
42
43
44
45
46
47
48
# File 'app/models/parsers/dilution_parser.rb', line 40

def each_well_and_parameters
  original_parser.each_well_and_parameters do |well, parameters|
    adjusted_parameters = parameters.slice(*UNSCALED)
    SCALED.each do |attribute|
      adjusted_parameters[attribute] = parameters[attribute] * scale_factor if parameters[attribute]
    end
    yield well, adjusted_parameters
  end
end