Class: TwitterCldr::Formatters::NumberFormatter
- Defined in:
- lib/twitter_cldr/formatters/numbers/number_formatter.rb
Direct Known Subclasses
Constant Summary collapse
- DEFAULT_SYMBOLS =
{ :group => ',', :decimal => '.', :plus_sign => '+', :minus_sign => '-' }
Instance Attribute Summary collapse
-
#symbols ⇒ Object
readonly
Returns the value of attribute symbols.
Attributes inherited from Base
Instance Method Summary collapse
- #format(number, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ NumberFormatter
constructor
A new instance of NumberFormatter.
Constructor Details
#initialize(options = {}) ⇒ NumberFormatter
Returns a new instance of NumberFormatter.
13 14 15 |
# File 'lib/twitter_cldr/formatters/numbers/number_formatter.rb', line 13 def initialize( = {}) @symbols = DEFAULT_SYMBOLS.merge(tokenizer.symbols) end |
Instance Attribute Details
#symbols ⇒ Object (readonly)
Returns the value of attribute symbols.
9 10 11 |
# File 'lib/twitter_cldr/formatters/numbers/number_formatter.rb', line 9 def symbols @symbols end |
Instance Method Details
#format(number, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 |
# File 'lib/twitter_cldr/formatters/numbers/number_formatter.rb', line 17 def format(number, = {}) opts = self.(number).merge() prefix, suffix, integer_format, fraction_format = *partition_tokens(self.get_tokens(number, opts)) int, fraction = parse_number(number, opts) result = integer_format.apply(int, opts) result << fraction_format.apply(fraction, opts) if fraction "#{prefix.to_s}#{result}#{suffix.to_s}" end |