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
32
33
# File 'app/models/qc_result_factory.rb', line 29

def build_resources(assets)
  assets.each do |asset|
    resources << Resource.new(asset.merge(qc_assay: qc_assay))
  end
end

#except_blank_wellsObject


35
36
37
# File 'app/models/qc_result_factory.rb', line 35

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: lot_number)
end

#qc_resultsObject


48
49
50
# File 'app/models/qc_result_factory.rb', line 48

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


39
40
41
42
43
44
45
46
# File 'app/models/qc_result_factory.rb', line 39

def save
  return false unless valid?

  ActiveRecord::Base.transaction do
    except_blank_wells.collect(&:save)
  end
  true
end