Class: Parsers::PlateReaderParser
- Inherits:
-
Object
- Object
- Parsers::PlateReaderParser
- Defined in:
- app/models/parsers/plate_reader_parser.rb
Defined Under Namespace
Classes: InvalidFile
Class Method Summary collapse
Instance Method Summary collapse
- #concentration(location) ⇒ Object
- #each_well_and_parameters ⇒ Object
- #get_column_for_header(sym) ⇒ Object
- #get_name_for_header(sym_name) ⇒ Object
- #get_row(location) ⇒ Object
- #headers ⇒ Object
-
#initialize(content) ⇒ PlateReaderParser
constructor
A new instance of PlateReaderParser.
- #locations ⇒ Object
- #table ⇒ Object
Constructor Details
#initialize(content) ⇒ PlateReaderParser
Returns a new instance of PlateReaderParser.
58 59 60 |
# File 'app/models/parsers/plate_reader_parser.rb', line 58 def initialize(content) @content = content end |
Class Method Details
.parses?(content) ⇒ Boolean
50 51 52 53 54 55 56 |
# 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 { |sym, pos| parser.get_column_for_header(sym) == pos } .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_parameters ⇒ Object
66 67 68 69 70 |
# File 'app/models/parsers/plate_reader_parser.rb', line 66 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 |
# 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) return pos if h.squish == name.squish unless name.nil? || h.nil? end end |
#get_name_for_header(sym_name) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'app/models/parsers/plate_reader_parser.rb', line 38 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
19 20 21 22 23 |
# File 'app/models/parsers/plate_reader_parser.rb', line 19 def get_row(location) letter = location[0].chr num = location.slice(1, location.length) table.detect { |row| row[0] == letter && row[1] == num } end |
#headers ⇒ Object
11 12 13 |
# File 'app/models/parsers/plate_reader_parser.rb', line 11 def headers @content[0] end |
#locations ⇒ Object
62 63 64 |
# File 'app/models/parsers/plate_reader_parser.rb', line 62 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 |
#table ⇒ Object
15 16 17 |
# File 'app/models/parsers/plate_reader_parser.rb', line 15 def table @content.slice(1, @content.length) end |