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]
TARGET_PLATE_PURPOSES =
'target_plate_purposes'
CONFIG_KEYS =
[TARGET_PLATE_PURPOSES]

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, #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


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

def qc_decision
  @qc_decision
end

Class Method Details

.headers(configuration) ⇒ Object


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

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

Instance Method Details

#assess!Object


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

def assess!
  @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


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

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