Class: TwitterCldr::Formatters::CurrencyFormatter
- Inherits:
-
NumberFormatter
- Object
- Base
- NumberFormatter
- TwitterCldr::Formatters::CurrencyFormatter
- Defined in:
- lib/twitter_cldr/formatters/numbers/currency_formatter.rb
Constant Summary collapse
- DEFAULT_CURRENCY_SYMBOL =
"$"
- DEFAULT_PRECISION =
2
Constants inherited from NumberFormatter
NumberFormatter::DEFAULT_SYMBOLS
Instance Attribute Summary
Attributes inherited from NumberFormatter
Attributes inherited from Base
Instance Method Summary collapse
- #default_format_options_for(number) ⇒ Object
- #format(number, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ CurrencyFormatter
constructor
A new instance of CurrencyFormatter.
Constructor Details
#initialize(options = {}) ⇒ CurrencyFormatter
Returns a new instance of CurrencyFormatter.
12 13 14 15 |
# File 'lib/twitter_cldr/formatters/numbers/currency_formatter.rb', line 12 def initialize( = {}) @tokenizer = TwitterCldr::Tokenizers::NumberTokenizer.new(:locale => self.extract_locale(), :type => :currency) super end |
Instance Method Details
#default_format_options_for(number) ⇒ Object
29 30 31 32 |
# File 'lib/twitter_cldr/formatters/numbers/currency_formatter.rb', line 29 def (number) precision = precision_from(number) { :precision => precision == 0 ? DEFAULT_PRECISION : precision } end |
#format(number, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/twitter_cldr/formatters/numbers/currency_formatter.rb', line 17 def format(number, = {}) if [:currency] currency ||= TwitterCldr::Shared::Currencies.for_code([:currency]) currency ||= TwitterCldr::Shared::Currencies.for_country([:currency]) currency ||= { :symbol => [:currency] } else currency = { :symbol => DEFAULT_CURRENCY_SYMBOL } end super(number, ).gsub('ยค', currency[:symbol]) end |