Class: Formatting::FormatCurrency

Inherits:
Object
  • Object
show all
Defined in:
lib/formatting/currency.rb

Instance Method Summary collapse

Constructor Details

#initialize(record_or_currency, amount_or_method, opts) ⇒ FormatCurrency

Returns a new instance of FormatCurrency.



14
15
16
17
18
19
20
21
# File 'lib/formatting/currency.rb', line 14

def initialize(record_or_currency, amount_or_method, opts)
  @record_or_currency = record_or_currency
  @amount_or_method = amount_or_method
  @opts = opts

  @format_string = opts.fetch(:format, "<amount> <currency>")
  @skip_currency = opts.fetch(:skip_currency, false)
end

Instance Method Details

#formatObject



23
24
25
26
27
28
29
30
31
# File 'lib/formatting/currency.rb', line 23

def format
  currency = determine_currency
  amount = determine_amount

  return "" if amount.nil?

  amount = FormatNumber.new(amount, opts).format
  apply_format_string(format_string, amount, currency)
end