Sha256: a6ed5e602d8653b0697bd5f39bad742b291c945caf2de9cd12831e54dee42d90

Contents?: true

Size: 442 Bytes

Versions: 3

Compression:

Stored size: 442 Bytes

Contents

module ShoppingCart
  class OrderDecorator < Drape::Decorator
    delegate_all

    def total_in_currency
      h.number_to_currency object.total
    end

    def total_with_delivery
      h.number_to_currency(object.total + delivery_price)
    end

    def discount
      h.number_to_percentage(object.coupon.discount, precision: 1)
    end

    private

    def delivery_price
      object.try(:delivery).try(:price) || 0
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
shopping-cart-0.1.2 app/decorators/shopping_cart/order_decorator.rb
shopping-cart-0.1.1 app/decorators/shopping_cart/order_decorator.rb
shopping-cart-0.1.0 app/decorators/shopping_cart/order_decorator.rb