Class: QcResultFactory
- Inherits:
-
Object
- Object
- QcResultFactory
- Includes:
- ActiveModel::Model
- Defined in:
- app/models/qc_result_factory.rb
Overview
QcResultFactory creates a QcResult record from API request
Defined Under Namespace
Classes: Resource
Instance Attribute Summary collapse
-
#lot_number ⇒ Object
Returns the value of attribute lot_number.
Instance Method Summary collapse
- #build_resources(assets) ⇒ Object
- #except_blank_wells ⇒ Object
-
#initialize(attributes = []) ⇒ QcResultFactory
constructor
A new instance of QcResultFactory.
- #qc_assay ⇒ Object
- #qc_results ⇒ Object
- #resources ⇒ Object
- #save ⇒ Object
Constructor Details
#initialize(attributes = []) ⇒ QcResultFactory
Returns a new instance of QcResultFactory.
12 13 14 15 16 17 18 19 |
# File 'app/models/qc_result_factory.rb', line 12 def initialize(attributes = []) if attributes.is_a?(Array) build_resources(attributes) else @lot_number = attributes[:lot_number] build_resources(attributes[:qc_results]) end end |
Instance Attribute Details
#lot_number ⇒ Object
Returns the value of attribute lot_number.
10 11 12 |
# File 'app/models/qc_result_factory.rb', line 10 def lot_number @lot_number end |
Instance Method Details
#build_resources(assets) ⇒ Object
29 30 31 |
# File 'app/models/qc_result_factory.rb', line 29 def build_resources(assets) assets.each { |asset| resources << Resource.new(asset.merge(qc_assay:)) } end |
#except_blank_wells ⇒ Object
33 34 35 |
# File 'app/models/qc_result_factory.rb', line 33 def except_blank_wells resources.reject(&:blank_well?) end |
#qc_assay ⇒ Object
25 26 27 |
# File 'app/models/qc_result_factory.rb', line 25 def qc_assay @qc_assay ||= QcAssay.new(lot_number:) end |
#qc_results ⇒ Object
44 45 46 |
# File 'app/models/qc_result_factory.rb', line 44 def qc_results resources.collect(&:qc_result) end |
#resources ⇒ Object
21 22 23 |
# File 'app/models/qc_result_factory.rb', line 21 def resources @resources ||= [] end |
#save ⇒ Object
37 38 39 40 41 42 |
# File 'app/models/qc_result_factory.rb', line 37 def save return false unless valid? ActiveRecord::Base.transaction { except_blank_wells.collect(&:save) } true end |