Class: QcResultFactory::Resource

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/qc_result_factory.rb

Overview

QcResultFactory::Resource

Instance Attribute Summary collapse

Instance Method Summary collapse

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_typeObject

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_versionObject

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

#assetObject (readonly)

Returns the value of attribute asset.



54
55
56
# File 'app/models/qc_result_factory.rb', line 54

def asset
  @asset
end

#asset_identifierObject (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

#barcodeObject

Returns the value of attribute barcode.



54
55
56
# File 'app/models/qc_result_factory.rb', line 54

def barcode
  @barcode
end

#cvObject

Returns the value of attribute cv.



52
53
54
# File 'app/models/qc_result_factory.rb', line 52

def cv
  @cv
end

#keyObject

Returns the value of attribute key.



52
53
54
# File 'app/models/qc_result_factory.rb', line 52

def key
  @key
end

#plateObject (readonly)

Returns the value of attribute plate.



54
55
56
# File 'app/models/qc_result_factory.rb', line 54

def plate
  @plate
end

#qc_assayObject

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_resultObject (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

#unitsObject

Returns the value of attribute units.



52
53
54
# File 'app/models/qc_result_factory.rb', line 52

def units
  @units
end

#uuidObject

Returns the value of attribute uuid.



54
55
56
# File 'app/models/qc_result_factory.rb', line 54

def uuid
  @uuid
end

#valueObject

Returns the value of attribute value.



52
53
54
# File 'app/models/qc_result_factory.rb', line 52

def value
  @value
end

#well_locationObject

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

Returns:

  • (Boolean)


133
134
135
# File 'app/models/qc_result_factory.rb', line 133

def blank_well?
  asset.blank? && well_location.present?
end

#build_assetObject

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 || barcode
  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

Returns:

  • (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

Returns:

  • (Boolean)


116
117
118
# File 'app/models/qc_result_factory.rb', line 116

def concentration?
  key == 'concentration'
end

#message_idObject



65
66
67
# File 'app/models/qc_result_factory.rb', line 65

def message_id
  "Asset identifier - #{asset_identifier || 'blank'}"
end

#parent_plateObject



69
70
71
# File 'app/models/qc_result_factory.rb', line 69

def parent_plate
  @parent_plate ||= plate.parent
end

#saveObject



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_wellObject



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

Returns:

  • (Boolean)


112
113
114
# File 'app/models/qc_result_factory.rb', line 112

def working_dilution?
  plate.instance_of? WorkingDilutionPlate
end