Class: Plurimath::NumberFormatter
- Inherits:
-
Object
- Object
- Plurimath::NumberFormatter
- Defined in:
- lib/plurimath/number_formatter.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#localize_number ⇒ Object
Returns the value of attribute localize_number.
-
#localizer_symbols ⇒ Object
Returns the value of attribute localizer_symbols.
-
#precision ⇒ Object
Returns the value of attribute precision.
Instance Method Summary collapse
-
#initialize(locale = "en", localize_number: nil, localizer_symbols: {}, precision: nil) ⇒ NumberFormatter
constructor
A new instance of NumberFormatter.
- #localized_number(number_string, locale: @locale, precision: @precision, format: {}) ⇒ Object
- #twitter_cldr_reader(locale: @locale) ⇒ Object
Constructor Details
#initialize(locale = "en", localize_number: nil, localizer_symbols: {}, precision: nil) ⇒ NumberFormatter
Returns a new instance of NumberFormatter.
7 8 9 10 11 12 |
# File 'lib/plurimath/number_formatter.rb', line 7 def initialize(locale = "en", localize_number: nil, localizer_symbols: {}, precision: nil) @locale = supported_locale(locale) @localize_number = localize_number @localizer_symbols = localizer_symbols @precision = precision end |
Instance Attribute Details
#locale ⇒ Object
Returns the value of attribute locale.
5 6 7 |
# File 'lib/plurimath/number_formatter.rb', line 5 def locale @locale end |
#localize_number ⇒ Object
Returns the value of attribute localize_number.
5 6 7 |
# File 'lib/plurimath/number_formatter.rb', line 5 def localize_number @localize_number end |
#localizer_symbols ⇒ Object
Returns the value of attribute localizer_symbols.
5 6 7 |
# File 'lib/plurimath/number_formatter.rb', line 5 def localizer_symbols @localizer_symbols end |
#precision ⇒ Object
Returns the value of attribute precision.
5 6 7 |
# File 'lib/plurimath/number_formatter.rb', line 5 def precision @precision end |
Instance Method Details
#localized_number(number_string, locale: @locale, precision: @precision, format: {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/plurimath/number_formatter.rb', line 14 def localized_number(number_string, locale: @locale, precision: @precision, format: {}) prev_symbols = symbols(locale).dup Formatter::NumericFormatter.new( supported_locale(locale), localize_number: localize_number, localizer_symbols: localizer_symbols, ).localized_number( number_string, locale: supported_locale(locale), precision: precision, format: format, ) ensure symbols(locale).replace(prev_symbols) end |
#twitter_cldr_reader(locale: @locale) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/plurimath/number_formatter.rb', line 30 def twitter_cldr_reader(locale: @locale) Formatter::NumericFormatter.new( supported_locale(locale), localize_number: localize_number, localizer_symbols: localizer_symbols, ).twitter_cldr_reader end |