Class: FlexStationData::ParsePlateReadings

Inherits:
Object
  • Object
show all
Includes:
Callable
Defined in:
lib/flex_station_data/services/parse_plate_readings.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(plate_data) ⇒ ParsePlateReadings

Returns a new instance of ParsePlateReadings.



15
16
17
# File 'lib/flex_station_data/services/parse_plate_readings.rb', line 15

def initialize(plate_data)
  @plate_data = plate_data
end

Class Method Details

.parse_row(row) ⇒ Object



61
62
63
64
# File 'lib/flex_station_data/services/parse_plate_readings.rb', line 61

def parse_row(row)
  time, temperature, *values = row
  [ parse_time(time), parse_value(temperature), *values.map(&method(:parse_value)) ]
end

.parse_time(t) ⇒ Object



48
49
50
51
52
53
# File 'lib/flex_station_data/services/parse_plate_readings.rb', line 48

def parse_time(t)
  return if t.blank?

  h, m, s = t.split(":").map(&:to_i)
  h * 60.0 + m + s / 60.0
end

.parse_value(v) ⇒ Object



55
56
57
58
59
# File 'lib/flex_station_data/services/parse_plate_readings.rb', line 55

def parse_value(v)
  Float(v)
rescue ArgumentError, TypeError
  v.presence
end

Instance Method Details

#callObject



43
44
45
# File 'lib/flex_station_data/services/parse_plate_readings.rb', line 43

def call
  [ times, temperatures, wells ]
end

#headersObject



27
28
29
# File 'lib/flex_station_data/services/parse_plate_readings.rb', line 27

def headers
  @headers ||= plate_data.detect(&method(:header_row?)).reverse.drop_while(&:blank?).reverse
end

#readings_blockObject



19
20
21
22
23
24
25
# File 'lib/flex_station_data/services/parse_plate_readings.rb', line 19

def readings_block
  @readings_block ||= plate_data
    .drop_while { |row| !header_row?(row) }
    .drop_while { |row| !sample_row?(row) }
    .take_while { |row| !end_row?(row) }
    .select     { |row| row.any?(&:present?) }
end

#temperaturesObject



35
36
37
# File 'lib/flex_station_data/services/parse_plate_readings.rb', line 35

def temperatures
  @temperatures ||= matrix.column(1).to_a.compact
end

#timesObject



31
32
33
# File 'lib/flex_station_data/services/parse_plate_readings.rb', line 31

def times
  @times ||= matrix.column(0).to_a.compact
end

#wellsObject



39
40
41
# File 'lib/flex_station_data/services/parse_plate_readings.rb', line 39

def wells
  Wells.new(wells_matrix)
end