Module: InvoiceBar::InvoiceBarHelper

Included in:
InvoicePDF, ReceiptPDF
Defined in:
app/helpers/invoice_bar/invoice_bar_helper.rb

Instance Method Summary collapse

Instance Method Details

#active_for_controller(controller) ⇒ Object

Defines an active state of the navbar item according to which controller is used.



5
6
7
# File 'app/helpers/invoice_bar/invoice_bar_helper.rb', line 5

def active_for_controller(controller)
  'active' if params[:controller].include? controller
end

#formatted_amount(cents, currency_symbol = '') ⇒ Object

Format money values using FormattedMoney. If specified, it uses a currency_symbol in front of the amount.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/helpers/invoice_bar/invoice_bar_helper.rb', line 17

def formatted_amount(cents, currency_symbol = '')
  begin
    results = FormattedMoney.amount(cents)
  rescue
    results = cents
  end

  if currency_symbol.blank?
    results
  else
    "#{currency_symbol} #{results}"
  end
end

#formatted_money(cents, currency_symbol = '') ⇒ Object



31
32
33
# File 'app/helpers/invoice_bar/invoice_bar_helper.rb', line 31

def formatted_money(cents, currency_symbol = '')
  formatted_amount(cents, currency_symbol)
end

#formatted_postcode(postcode) ⇒ Object

Format Czech (and a like) 5-digit-long postcode.



10
11
12
13
# File 'app/helpers/invoice_bar/invoice_bar_helper.rb', line 10

def formatted_postcode(postcode)
  return postcode unless postcode.to_s.length == 5
  postcode.to_s.gsub(/^(\d\d\d)(\d\d)$/, '\\1 \\2')
end