Sha256: 9cb53cee4793062d14bb6c2dba7fafbeefe689a445c2294e1c966dd41507467f

Contents?: true

Size: 743 Bytes

Versions: 9

Compression:

Stored size: 743 Bytes

Contents

module ShopDiscounts
  module Models
    module Purchaseable
      
      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
      
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
radiant-shop_discounts-extension-0.0.11 lib/shop_discounts/models/purchaseable.rb
radiant-shop_discounts-extension-0.0.10 lib/shop_discounts/models/purchaseable.rb
radiant-shop_discounts-extension-0.0.9 lib/shop_discounts/models/purchaseable.rb
radiant-shop_discounts-extension-0.0.8 lib/shop_discounts/models/purchaseable.rb
radiant-shop_discounts-extension-0.0.7 lib/shop_discounts/models/purchaseable.rb
radiant-shop_discounts-extension-0.0.6 lib/shop_discounts/models/purchaseable.rb
radiant-shop_discounts-extension-0.0.4 lib/shop_discounts/models/purchaseable.rb
radiant-shop_discounts-extension-0.0.3 lib/shop_discounts/models/purchaseable.rb
radiant-shop_discounts-extension-0.0.1 lib/shop_discounts/models/purchaseable.rb