Class: Auth::Work::Template

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Document
Defined in:
app/models/auth/work/template.rb

Instance Method Summary collapse

Instance Method Details

#add_item_to_output_hash(output_hash, template_index) ⇒ Object



15
16
17
18
# File 'app/models/auth/work/template.rb', line 15

def add_item_to_output_hash(output_hash,template_index) 
  output_hash[product_id_to_generate] = [{:template_id => self.id.to_s, :from => self.start_amount, :to => self.amount_generated, :template_index => template_index, :original_template_id => self.id.to_s}]
  output_hash
end

#summate_items(output_hash, template_index) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/auth/work/template.rb', line 20

def summate_items(output_hash,template_index)
  template_key = self.summate_with_index || template_index
  output_hash[product_id_to_generate] = []
  self.cycle.output_array.reverse.each_with_index {|prev_citem_output,key|
    prev_citem_output.each_key do |product_id|
      tmp = prev_citem_output[product_id]
      if tmp[:template_index] == template_key
        if (tmp[:to] + self.amount_generated) > self.create_new_item_if_amount_crosses
          add_item_to_output_hash(output_hash,template_index)
        else
          output_hash[product_id_to_generate] << {
            :template_id => tmp[:original_template_id], 
            :from => tmp[:to],
            :to => tmp[:to] + self.amount_generated,
            :template_index => template_index,
            :original_template_id => self.id.to_s
          }
        end
      end        
    end
  }
end