Class: FlexStationData::Presenters::SampleHash

Inherits:
Object
  • Object
show all
Includes:
Callable[:present]
Defined in:
lib/flex_station_data/presenters/sample_hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(times, sample, **options) ⇒ SampleHash

Returns a new instance of SampleHash.



14
15
16
17
18
# File 'lib/flex_station_data/presenters/sample_hash.rb', line 14

def initialize(times, sample, **options)
  @times = times
  @sample = sample
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



12
13
14
# File 'lib/flex_station_data/presenters/sample_hash.rb', line 12

def options
  @options
end

#quality_controlObject (readonly)

Returns the value of attribute quality_control.



12
13
14
# File 'lib/flex_station_data/presenters/sample_hash.rb', line 12

def quality_control
  @quality_control
end

#sampleObject (readonly)

Returns the value of attribute sample.



12
13
14
# File 'lib/flex_station_data/presenters/sample_hash.rb', line 12

def sample
  @sample
end

#timesObject (readonly)

Returns the value of attribute times.



12
13
14
# File 'lib/flex_station_data/presenters/sample_hash.rb', line 12

def times
  @times
end

Instance Method Details

#errorsObject



20
21
22
# File 'lib/flex_station_data/presenters/sample_hash.rb', line 20

def errors
  @errors ||= SampleQuality.call(sample, **options).reject(&:good?)
end

#errors?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/flex_station_data/presenters/sample_hash.rb', line 24

def errors?
  errors.present?
end

#errors_hashObject



28
29
30
# File 'lib/flex_station_data/presenters/sample_hash.rb', line 28

def errors_hash
  { "error" => errors.first&.to_s }
end

#presentObject



42
43
44
# File 'lib/flex_station_data/presenters/sample_hash.rb', line 42

def present
  { "sample" => sample.label }.merge(wells_hash).merge(errors_hash).merge(regression_hash)
end

#regression_hashObject



36
37
38
39
40
# File 'lib/flex_station_data/presenters/sample_hash.rb', line 36

def regression_hash
  return SampleRegressionHash.headers.zip([]).to_h if errors?

  SampleRegressionHash.present(times, sample.mean, **options).transform_values(&:first)
end

#wells_hashObject



32
33
34
# File 'lib/flex_station_data/presenters/sample_hash.rb', line 32

def wells_hash
  { "wells" => sample.wells.join(", ") }
end