Class: Pricing

Inherits:
Object
  • Object
show all
Defined in:
lib/pricing_observer.rb

Instance Method Summary collapse

Constructor Details

#initialize(order) ⇒ Pricing

Returns a new instance of Pricing.



26
27
28
29
# File 'lib/pricing_observer.rb', line 26

def initialize(order)    
order.add_observer(self)
puts "observer initialized"
end

Instance Method Details

#pricing_by_hitObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/pricing_observer.rb', line 31

def pricing_by_hit
    #order_record = OrderItem.last
    #prod = Product.find(order_record.product_id)
  puts("before product assumption")
  products = Product.all
  puts("after product assumption")
    
   products.each do |prod|
    prod.price = 12
    puts(prod.hit.inspect)
       case prod.hit
       when 1
          prod.offerPrice = prod.offerPrice + (prod.offerPrice/50)
       when 2
          prod.offerPrice = prod.offerPrice - (prod.offerPrice/100)
       when 3
          prod.offerPrice = prod.offerPrice - (prod.offerPrice/95)
       when 4
          prod.offerPrice = prod.offerPrice - (prod.offerPrice/90)
       when 5
          prod.offerPrice = prod.offerPrice - (prod.offerPrice/85)
       when 6
          prod.offerPrice = prod.offerPrice - (prod.offerPrice/80)
       when 7
          prod.offerPrice = prod.offerPrice - (prod.offerPrice/75)
       when 8
          prod.offerPrice = prod.offerPrice - (prod.offerPrice/70)
       when 9
          prod.offerPrice = prod.offerPrice - (prod.offerPrice/65)
       when 10
          prod.offerPrice = prod.offerPrice - (prod.offerPrice/60)
       else
          prod.offerPrice = 5
       end
      if(prod.offerPrice < 5)
          prod.offerPrice = 5
      elsif (prod.offerPrice > 12)
          prod.offerPrice = 5
      end
    prod.save
   end
end