Module: Philiprehberger::Money::Formatting

Included in:
Philiprehberger::Money
Defined in:
lib/philiprehberger/money/formatting.rb

Overview

Formatting methods for Money objects

Instance Method Summary collapse

Instance Method Details

#format(symbol: true, code: false, thousands: true) ⇒ String

Format the money amount as a string

Parameters:

  • symbol (Boolean) (defaults to: true)

    include the currency symbol (default: true)

  • code (Boolean) (defaults to: false)

    append the currency code (default: false)

  • thousands (Boolean) (defaults to: true)

    include thousands separators (default: true)

Returns:

  • (String)

    formatted money string



13
14
15
16
17
18
# File 'lib/philiprehberger/money/formatting.rb', line 13

def format(symbol: true, code: false, thousands: true)
  formatted = format_amount(thousands: thousands)
  result = build_formatted_string(formatted, symbol: symbol)
  result = "#{result} #{currency.code.upcase}" if code
  result
end

#to_sString

Returns formatted money string (delegates to #format).

Returns:

  • (String)

    formatted money string (delegates to #format)



21
22
23
# File 'lib/philiprehberger/money/formatting.rb', line 21

def to_s
  format
end