Class: Billing::Factory::Sequencing

Inherits:
Base
  • Object
show all
Defined in:
app/models/billing/factory/sequencing.rb

Constant Summary

Constants inherited from Base

Base::NO_PROJECT_COST_CODE

Instance Attribute Summary collapse

Attributes inherited from Base

#billing_product, #request

Instance Method Summary collapse

Methods inherited from Base

#billing_product_code, #billing_product_description, #passed_date, #passed_date=, #project_cost_code

Constructor Details

#initialize(attributes = {}) ⇒ Sequencing

Returns a new instance of Sequencing


8
9
10
11
# File 'app/models/billing/factory/sequencing.rb', line 8

def initialize(attributes = {})
  super
  self.aliquots = request
end

Instance Attribute Details

#aliquotsObject

Returns the value of attribute aliquots


4
5
6
# File 'app/models/billing/factory/sequencing.rb', line 4

def aliquots
  @aliquots
end

Instance Method Details

#create!Object

TODO: create should be abstracted.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/models/billing/factory/sequencing.rb', line 20

def create!
  return unless valid?

  aliquots.count_by_project_cost_code.each do |cost_code, count|
    Billing::Item.create!(
      request: request,
      project_cost_code: project_cost_code(cost_code),
      units: units(count, aliquots.length),
      billing_product_code: billing_product_code,
      billing_product_description: billing_product_description,
      billing_product_name: billing_product_name,
      request_passed_date: passed_date
    )
  end
end

#units(count, total) ⇒ Object


36
37
38
# File 'app/models/billing/factory/sequencing.rb', line 36

def units(count, total)
  (count.to_f / total * 100).round
end