Class: Pricing
- Inherits:
-
Object
- Object
- Pricing
- Defined in:
- lib/pricing_observer.rb
Overview
this prcing class is the oberser class that triggers the observer functionality
Instance Method Summary collapse
-
#initialize(order) ⇒ Pricing
constructor
this method initializes the class and adds the observer object to observer class.
-
#pricing_by_hit(check_store) ⇒ Object
this is the logical pricing method that is triggered by the observer when ever the condition is met to be executed.
Constructor Details
#initialize(order) ⇒ Pricing
this method initializes the class and adds the observer object to observer class
32 33 34 35 |
# File 'lib/pricing_observer.rb', line 32 def initialize(order) order.add_observer(self) puts "observer initialized" end |
Instance Method Details
#pricing_by_hit(check_store) ⇒ Object
this is the logical pricing method that is triggered by the observer when ever the condition is met to be executed.
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 73 74 75 76 77 78 79 80 |
# File 'lib/pricing_observer.rb', line 37 def pricing_by_hit(check_store) #order_record = OrderItem.last #prod = Product.find(order_record.product_id) check_store.each do |store_with_id| puts("before product assumption") products = Product.where(store_detail_id: store_with_id) puts("after product assumption") products.each do |prod| #prod.price = 43 puts(prod.hit.inspect) case prod.hit when 1 prod.offerPrice = prod.offerPrice + (prod.offerPrice/4) when 2 prod.offerPrice = prod.offerPrice - (prod.offerPrice/36) when 3 prod.offerPrice = prod.offerPrice - (prod.offerPrice/32) when 4 prod.offerPrice = prod.offerPrice - (prod.offerPrice/28) when 5 prod.offerPrice = prod.offerPrice - (prod.offerPrice/24) when 6 prod.offerPrice = prod.offerPrice - (prod.offerPrice/20) when 7 prod.offerPrice = prod.offerPrice - (prod.offerPrice/16) when 8 prod.offerPrice = prod.offerPrice - (prod.offerPrice/12) when 9 prod.offerPrice = prod.offerPrice - (prod.offerPrice/8) when 10 prod.offerPrice = prod.offerPrice - (prod.offerPrice/4) else prod.offerPrice = 18 end if(prod.offerPrice < 15) prod.offerPrice = 15 elsif(prod.offerPrice > 45) prod.offerPrice = 30 end prod.save end end end |