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


21
22
23
24
# File 'app/models/parsers/dilution_parser.rb', line 21

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


13
14
15
# File 'app/models/parsers/dilution_parser.rb', line 13

def original_parser
  @original_parser
end

#scale_factorObject (readonly)

Other parameters (eg. volume) will not propagate


13
14
15
# File 'app/models/parsers/dilution_parser.rb', line 13

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


30
31
32
# File 'app/models/parsers/dilution_parser.rb', line 30

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


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

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