Module: ShopDiscounts::Models::Purchaseable
- Defined in:
- lib/shop_discounts/models/purchaseable.rb
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/shop_discounts/models/purchaseable.rb', line 5 def self.included(base) base.class_eval do def discount discount = BigDecimal.new('0.00') discounts.map { |d| discount += d.amount } # Maximum discount is 100% discount = [discount,100.0].min # Convert to a percentage discount * 0.01 end def discounted (value * discount) end alias_method :value, :price def price result = BigDecimal.new('0.00') result = value - discounted end end end |