Class: QcResultFactory

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_numberObject

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_wellsObject



33
34
35
# File 'app/models/qc_result_factory.rb', line 33

def except_blank_wells
  resources.reject(&:blank_well?)
end

#qc_assayObject



25
26
27
# File 'app/models/qc_result_factory.rb', line 25

def qc_assay
  @qc_assay ||= QcAssay.new(lot_number:)
end

#qc_resultsObject



44
45
46
# File 'app/models/qc_result_factory.rb', line 44

def qc_results
  resources.collect(&:qc_result)
end

#resourcesObject



21
22
23
# File 'app/models/qc_result_factory.rb', line 21

def resources
  @resources ||= []
end

#saveObject



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