Class: QcResultFactory::Resource
- Inherits:
-
Object
- Object
- QcResultFactory::Resource
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/qc_result_factory.rb
Overview
QcResultFactory::Resource
Instance Attribute Summary collapse
-
#assay_type ⇒ Object
Returns the value of attribute assay_type.
-
#assay_version ⇒ Object
Returns the value of attribute assay_version.
-
#asset ⇒ Object
readonly
Returns the value of attribute asset.
-
#asset_identifier ⇒ Object
readonly
Returns the value of attribute asset_identifier.
-
#barcode ⇒ Object
Returns the value of attribute barcode.
-
#cv ⇒ Object
Returns the value of attribute cv.
-
#key ⇒ Object
Returns the value of attribute key.
-
#plate ⇒ Object
readonly
Returns the value of attribute plate.
-
#qc_assay ⇒ Object
Returns the value of attribute qc_assay.
-
#qc_result ⇒ Object
readonly
Returns the value of attribute qc_result.
-
#units ⇒ Object
Returns the value of attribute units.
-
#uuid ⇒ Object
Returns the value of attribute uuid.
-
#value ⇒ Object
Returns the value of attribute value.
-
#well_location ⇒ Object
Returns the value of attribute well_location.
Instance Method Summary collapse
- #blank_well? ⇒ Boolean
-
#build_asset ⇒ Object
This is where the complexity is.
- #can_update_parent_well? ⇒ Boolean
- #concentration? ⇒ Boolean
-
#initialize(attributes = {}) ⇒ Resource
constructor
A new instance of Resource.
- #message_id ⇒ Object
- #parent_plate ⇒ Object
- #save ⇒ Object
- #update_parent_well ⇒ Object
- #working_dilution? ⇒ Boolean
Constructor Details
#initialize(attributes = {}) ⇒ Resource
Returns a new instance of Resource.
58 59 60 61 62 63 |
# File 'app/models/qc_result_factory.rb', line 58 def initialize(attributes = {}) super(attributes) @asset = build_asset @qc_result = QcResult.new(asset:, key:, value:, units:, cv:, assay_type:, assay_version:, qc_assay:) end |
Instance Attribute Details
#assay_type ⇒ Object
Returns the value of attribute assay_type.
52 53 54 |
# File 'app/models/qc_result_factory.rb', line 52 def assay_type @assay_type end |
#assay_version ⇒ Object
Returns the value of attribute assay_version.
52 53 54 |
# File 'app/models/qc_result_factory.rb', line 52 def assay_version @assay_version end |
#asset ⇒ Object (readonly)
Returns the value of attribute asset.
54 55 56 |
# File 'app/models/qc_result_factory.rb', line 54 def asset @asset end |
#asset_identifier ⇒ Object (readonly)
Returns the value of attribute asset_identifier.
54 55 56 |
# File 'app/models/qc_result_factory.rb', line 54 def asset_identifier @asset_identifier end |
#barcode ⇒ Object
Returns the value of attribute barcode.
54 55 56 |
# File 'app/models/qc_result_factory.rb', line 54 def @barcode end |
#cv ⇒ Object
Returns the value of attribute cv.
52 53 54 |
# File 'app/models/qc_result_factory.rb', line 52 def cv @cv end |
#key ⇒ Object
Returns the value of attribute key.
52 53 54 |
# File 'app/models/qc_result_factory.rb', line 52 def key @key end |
#plate ⇒ Object (readonly)
Returns the value of attribute plate.
54 55 56 |
# File 'app/models/qc_result_factory.rb', line 54 def plate @plate end |
#qc_assay ⇒ Object
Returns the value of attribute qc_assay.
52 53 54 |
# File 'app/models/qc_result_factory.rb', line 52 def qc_assay @qc_assay end |
#qc_result ⇒ Object (readonly)
Returns the value of attribute qc_result.
54 55 56 |
# File 'app/models/qc_result_factory.rb', line 54 def qc_result @qc_result end |
#units ⇒ Object
Returns the value of attribute units.
52 53 54 |
# File 'app/models/qc_result_factory.rb', line 52 def units @units end |
#uuid ⇒ Object
Returns the value of attribute uuid.
54 55 56 |
# File 'app/models/qc_result_factory.rb', line 54 def uuid @uuid end |
#value ⇒ Object
Returns the value of attribute value.
52 53 54 |
# File 'app/models/qc_result_factory.rb', line 52 def value @value end |
#well_location ⇒ Object
Returns the value of attribute well_location.
52 53 54 |
# File 'app/models/qc_result_factory.rb', line 52 def well_location @well_location end |
Instance Method Details
#blank_well? ⇒ Boolean
133 134 135 |
# File 'app/models/qc_result_factory.rb', line 133 def blank_well? asset.blank? && well_location.present? end |
#build_asset ⇒ Object
This is where the complexity is. First we need to find the uuid object. Then we need to return the asset it relates to. If the object is a sample we need to return it’s primary receptacle which will be a well. If the object is a tube then do nothing just return the asset. If a well location is passed then assume it is a plate so we need to return the associated well.
96 97 98 99 100 101 102 103 |
# File 'app/models/qc_result_factory.rb', line 96 def build_asset asset = uuid || return if asset.blank? return asset if well_location.blank? @plate = Plate.find(asset.id) plate.find_well_by_map_description(well_location) end |
#can_update_parent_well? ⇒ Boolean
120 121 122 |
# File 'app/models/qc_result_factory.rb', line 120 def can_update_parent_well? working_dilution? && concentration? && well_location.present? && plate.dilution_factor.present? end |
#concentration? ⇒ Boolean
116 117 118 |
# File 'app/models/qc_result_factory.rb', line 116 def concentration? key == 'concentration' end |
#message_id ⇒ Object
65 66 67 |
# File 'app/models/qc_result_factory.rb', line 65 def "Asset identifier - #{asset_identifier || 'blank'}" end |
#parent_plate ⇒ Object
69 70 71 |
# File 'app/models/qc_result_factory.rb', line 69 def parent_plate @parent_plate ||= plate.parent end |
#save ⇒ Object
105 106 107 108 109 110 |
# File 'app/models/qc_result_factory.rb', line 105 def save return false unless valid? update_parent_well qc_result.save end |
#update_parent_well ⇒ Object
124 125 126 127 128 129 130 131 |
# File 'app/models/qc_result_factory.rb', line 124 def update_parent_well return unless can_update_parent_well? well = parent_plate.find_well_by_map_description(well_location) parent_qc_result = QcResult.new(qc_result.attributes.merge(asset: well, value: value.to_f * plate.dilution_factor)) parent_qc_result.save! end |
#working_dilution? ⇒ Boolean
112 113 114 |
# File 'app/models/qc_result_factory.rb', line 112 def working_dilution? plate.instance_of? WorkingDilutionPlate end |