Class: ProductCriteria::Advanced

Inherits:
Basic
  • Object
show all
Defined in:
app/models/product_criteria/advanced.rb

Overview

Advanced Product Criteria can have ‘unprocessable’ thresholds as well as fails.

Constant Summary collapse

STATE_ORDER =
%w[failed unprocessable].freeze
TARGET_PLATE_PURPOSES =
'target_plate_purposes'
CONFIG_KEYS =
[TARGET_PLATE_PURPOSES].freeze

Constants inherited from Basic

Basic::EXTENDED_ATTRIBUTES, Basic::FAILED_STATE, Basic::GENDER_MARKER_MAPS, Basic::METHOD_ALIAS, Basic::PASSSED_STATE, Basic::SUPPORTED_SAMPLE, Basic::SUPPORTED_SAMPLE_METADATA, Basic::SUPPORTED_WELL_ATTRIBUTES, Basic::UnknownSpecification

Instance Attribute Summary collapse

Attributes inherited from Basic

#comment, #params, #passed, #values

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Basic

available_criteria, #concentration_from_normalization, #conflicting_gender_markers, #initialize, #metrics, #most_recent_concentration_from_target_well_by_updating_date, #plate_barcode, #sample_gender, #storage_location, #total_micrograms, #well_location

Constructor Details

This class inherits a constructor from ProductCriteria::Basic

Instance Attribute Details

#qc_decisionObject (readonly)

Returns the value of attribute qc_decision.



5
6
7
# File 'app/models/product_criteria/advanced.rb', line 5

def qc_decision
  @qc_decision
end

Class Method Details

.headers(configuration) ⇒ Object



14
15
16
# File 'app/models/product_criteria/advanced.rb', line 14

def headers(configuration)
  (configuration.slice(*STATE_ORDER).values.reduce(&:merge).keys + [:comment]).uniq
end

Instance Method Details

#assess!Object

rubocop:todo Metrics/MethodLength



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/models/product_criteria/advanced.rb', line 26

def assess! # rubocop:todo Metrics/AbcSize
  @qc_decision = 'passed'
  STATE_ORDER.each do |decision|
    params
      .fetch(decision, [])
      .each do |attribute, comparisons|
        value = fetch_attribute(attribute)
        values[attribute] = value

        if value.blank? && comparisons.present?
          invalid(attribute, '%s has not been recorded', decision)
          next
        end

        comparisons.each do |comparison, target|
          value.send(method_for(comparison), target) || invalid(attribute, message_for(comparison), decision)
        end
      end
  end
end

#invalid(attribute, message, decision) ⇒ Object



19
20
21
22
23
# File 'app/models/product_criteria/advanced.rb', line 19

def invalid(attribute, message, decision)
  @qc_decision = decision
  @comment << (message % attribute.to_s.humanize)
  @comment.uniq!
end