Class: Parsers::QuantParser

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

Defined Under Namespace

Classes: InvalidFile

Constant Summary collapse

HEADER_IDENTIFIER =
'Headers'.freeze
LOCATION_HEADER =
'Well Location'.freeze
COLUMN_MAPS =
{
  'concentration' => ['concentration', 'ng/ul'],
  'molarity' => ['molarity', 'nmol/l'],
  'volume' => %w[volume ul],
  'rin' => %w[RIN RIN]
}.freeze
VALUE_REGEX =

Extract decimals from columns. Ignores preceding ( and allows optional decimal point Any characters after the digits are ignored. eg. 12.345 => 12.345 13 => 13 (45.2) => 45.2 sausages => nil 34 ng/ul => 35

/\A\({0,1}(?<decimal>\d+\.{0,1}\d*)/

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ QuantParser

Returns a new instance of QuantParser


29
30
31
# File 'app/models/parsers/quant_parser.rb', line 29

def initialize(content)
  @content = content
end

Class Method Details

.headers_index(content) ⇒ Object


33
34
35
# File 'app/models/parsers/quant_parser.rb', line 33

def self.headers_index(content)
  content.find_index { |l| l[0] == HEADER_IDENTIFIER }
end

.parses?(content) ⇒ Boolean

Returns:

  • (Boolean)

37
38
39
# File 'app/models/parsers/quant_parser.rb', line 37

def self.parses?(content)
  (content[0][0] == 'Assay Plate Barcode') && headers_index(content)
end

Instance Method Details

#each_well_and_parametersObject


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

def each_well_and_parameters
  data_section.each do |row|
    # If location is nil or blank, ignore the row
    next if row[location_index].nil? || row[location_index].strip.blank?

    yield(row[location_index], qc_values_for_row(row))
  end
end