Class: Parsers::PlateReaderParser

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

Defined Under Namespace

Classes: InvalidFile

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content) ⇒ PlateReaderParser

Returns a new instance of PlateReaderParser


57
58
59
# File 'app/models/parsers/plate_reader_parser.rb', line 57

def initialize(content)
  @content = content
end

Class Method Details

.parses?(content) ⇒ Boolean

Returns:

  • (Boolean)

50
51
52
53
54
55
# File 'app/models/parsers/plate_reader_parser.rb', line 50

def self.parses?(content)
  parser = Parsers::PlateReaderParser.new(content)
  %i[row col content raw_data concentration].each_with_index.map do |sym, pos|
    parser.get_column_for_header(sym) == pos
  end.all?
end

Instance Method Details

#concentration(location) ⇒ Object


25
26
27
28
29
# File 'app/models/parsers/plate_reader_parser.rb', line 25

def concentration(location)
  get_row(location)[get_column_for_header(:concentration)]
rescue NoMethodError # Ugh! I want to catch these where they happen
  raise InvalidFile
end

#each_well_and_parametersObject


65
66
67
68
69
# File 'app/models/parsers/plate_reader_parser.rb', line 65

def each_well_and_parameters
  locations.each do |location_name|
    yield(location_name, { 'concentration' => Unit.new(concentration(location_name), 'ng/ul') })
  end
end

#get_column_for_header(sym) ⇒ Object


31
32
33
34
35
36
37
38
# File 'app/models/parsers/plate_reader_parser.rb', line 31

def get_column_for_header(sym)
  headers.each_with_index do |h, pos|
    name = get_name_for_header(sym)
    unless name.nil? || h.nil?
      return pos if h.squish == name.squish
    end
  end
end

#get_name_for_header(sym_name) ⇒ Object


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

def get_name_for_header(sym_name)
  {
    row: 'Well Row',
    col: 'Well Col',
    content: 'Content',
    raw_data: 'Raw Data (485/520)',
    concentration: 'Linear regression fit based on Raw Data (485/520)'
  }[sym_name]
end

#get_row(location) ⇒ Object


17
18
19
20
21
22
23
# File 'app/models/parsers/plate_reader_parser.rb', line 17

def get_row(location)
  letter = location[0].chr
  num = location.slice(1, location.length)
  table.detect do |row|
    row[0] == letter && row[1] == num
  end
end

#headersObject


9
10
11
# File 'app/models/parsers/plate_reader_parser.rb', line 9

def headers
  @content[0]
end

#locationsObject


61
62
63
# File 'app/models/parsers/plate_reader_parser.rb', line 61

def locations
  table.sort { |a, b| a[0] <=> b[0] && a[1].to_i <=> b[1].to_i }.map { |l| l[0] + l[1] }
end

#tableObject


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

def table
  @content.slice(1, @content.length)
end