Sha256: b0696b6666f39ede52c121f47b6e8096466bd849cefd1fb8ff0b475a7ae28cec

Contents?: true

Size: 958 Bytes

Versions: 1

Compression:

Stored size: 958 Bytes

Contents

# frozen_string_literal: true

require "matrix"
require "active_support/core_ext"

require "flex_station_data/concerns/service"

module FlexStationData
  class ParseSampleMap
    include Concerns::Service

    attr_reader :plate_data

    def initialize(plate_data)
      @plate_data = plate_data
    end

    def sample_map_rows
      plate_data
        .drop_while { |row| !sample_map_header?(row) }
        .drop(1)
        .take_while { |row| !empty_row?(row) }
        .map(&method(:parse_row))
    end

    def call
      sample_map_rows.each_with_object([]) do |(label, well), memo|
        memo << [ label, [] ] if label.present?
        memo.last.last << well
      end.to_h
    end

    private

    def parse_row(row)
      row.take(2).map(&:presence)
    end

    def empty_row?(row)
      row.all?(&:blank?)
    end

    def sample_map_header?(row)
      row[0].to_s =~ /\A\s*Sample\s*\z/i && row[1].to_s =~ /\A\s*Wells\s*\z/i
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flex-station-data-1.0.2 lib/flex_station_data/services/parse_sample_map.rb