class Pricing
this prcing class is the oberser class that triggers the observer functionality
Public Class Methods
new(order)
click to toggle source
this method initializes the class and adds the observer object to observer class
# File lib/pricing_observer.rb, line 32 def initialize(order) order.add_observer(self) puts "observer initialized" end
Public Instance Methods
pricing_by_hit(check_store)
click to toggle source
this is the logical pricing method that is triggered by the observer when ever the condition is met to be executed.
# 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/15) when 2 prod.offerPrice = prod.offerPrice - (prod.offerPrice/24) when 3 prod.offerPrice = prod.offerPrice - (prod.offerPrice/22) when 4 prod.offerPrice = prod.offerPrice - (prod.offerPrice/20) when 5 prod.offerPrice = prod.offerPrice - (prod.offerPrice/18) when 6 prod.offerPrice = prod.offerPrice - (prod.offerPrice/16) when 7 prod.offerPrice = prod.offerPrice - (prod.offerPrice/14) when 8 prod.offerPrice = prod.offerPrice - (prod.offerPrice/12) when 9 prod.offerPrice = prod.offerPrice - (prod.offerPrice/10) when 10 prod.offerPrice = prod.offerPrice - (prod.offerPrice/8) 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