Module: Custom::PriceHelper

Included in:
Lib::Boats::RentPricePerSeason, Lib::Boats::SalePrice
Defined in:
app/helpers/custom/price_helper.rb

Instance Method Summary collapse

Instance Method Details

#price_discount(object, attr) ⇒ Object

Parameters:

  • object (Boat)


6
7
8
9
10
11
12
13
14
# File 'app/helpers/custom/price_helper.rb', line 6

def price_discount(object, attr)
  price    = object.attributes[currency_attribute_name(attr)]
  discount = object.attributes["#{attr}_discount"]
  return ''    if price.nil?

  return price if discount.nil?

  price - (price / 100 * discount)
end

#price_format(object, attr, options = {}) ⇒ Object

Parameters:

  • object (Boat)


18
19
20
21
22
23
24
25
26
27
# File 'app/helpers/custom/price_helper.rb', line 18

def price_format(object, attr, options = {})
  price = options[:discounted] ? price_discount(object, attr) : object.attributes[currency_attribute_name(attr, options[:currency])]
  return '' if price.blank?

  unit  = currency_symbol options[:currency]
  price = number_to_currency(price, unit: unit).to_s
  price = price            + options[:postfix] if options[:postfix]
  price = options[:prefix] + price             if options[:prefix]
  price
end