Class: TwitterCldr::Formatters::CurrencyFormatter

Inherits:
NumberFormatter show all
Defined in:
lib/twitter_cldr/formatters/numbers/currency_formatter.rb

Instance Attribute Summary

Attributes inherited from NumberFormatter

#data_reader

Attributes inherited from Formatter

#data_reader

Instance Method Summary collapse

Methods inherited from NumberFormatter

#initialize, #truncate_number

Methods inherited from Formatter

#initialize

Constructor Details

This class inherits a constructor from TwitterCldr::Formatters::NumberFormatter

Instance Method Details

#format(tokens, number, options = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/twitter_cldr/formatters/numbers/currency_formatter.rb', line 10

def format(tokens, number, options = {})
  options[:currency] ||= "USD"
  options[:locale] ||= :en
  currency = TwitterCldr::Shared::Currencies.for_code(options[:currency], options[:locale])
  currency ||= {
    currency:    options[:currency],
    symbol:      options[:currency],
    cldr_symbol: options[:currency]
  }

  # overwrite with explicit symbol if given
  currency[:symbol] = options[:symbol] if options[:symbol]

  digits_and_rounding = resource(options[:currency])
  options[:precision] ||= digits_and_rounding[:digits]
  options[:rounding] ||= digits_and_rounding[:rounding]

  symbol = options[:use_cldr_symbol] ? currency[:cldr_symbol] : currency[:symbol]
  symbol ||= currency[:currency].to_s
  super.gsub('ยค', symbol)
end