Module: StripeInvoice::InvoicesHelper

Defined in:
app/helpers/stripe_invoice/invoices_helper.rb

Instance Method Summary collapse

Instance Method Details

#format_currency(amount, currency) ⇒ Object Also known as: fc

nicely formats the amount and currency



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 'app/helpers/stripe_invoice/invoices_helper.rb', line 5

def format_currency(amount, currency)
  
  currency = currency.upcase()
  # assuming that all currencies are split into 100 parts is probably wrong
  # on an i18n scale but it works for USD, EUR and LBP
  # TODO fix this maybe?
  amount = amount / 100
  options = {
    # use comma for euro 
    separator: currency == 'EUR' ? ',' : '.', 
    delimiter: currency == 'EUR' ? '.' : ',',
    format: currency == 'EUR' ? '%n %u' : '%u%n',
  }
  case currency
  when 'EUR'
    options[:unit] = '' 
  when 'LBP'
    options[:unit] = '£'
  when 'USD'
    options[:unit] = '$'
  else
    options[:unit] = currency
  end
  return number_to_currency(amount, options)
end