Class: Moolah::Formatter

Inherits:
Object
  • Object
show all
Defined in:
lib/moolah/formatter.rb

Instance Method Summary collapse

Constructor Details

#initialize(money) ⇒ Formatter

Returns a new instance of Formatter.



4
5
6
# File 'lib/moolah/formatter.rb', line 4

def initialize(money)
  @money = money
end

Instance Method Details

#format(symbol: true, delimit: true) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/moolah/formatter.rb', line 8

def format(symbol: true, delimit: true)
  str = ''
  str << currency_symbol if symbol
  str << formatted_amount
  str.gsub!(thousand_regex, "\\1#{currency_thousand_delimiter}") if delimit
  str
end

#format_fx_rateObject



16
17
18
# File 'lib/moolah/formatter.rb', line 16

def format_fx_rate
  sprintf('%.4f', money.fx_rate)
end