Class: Plurimath::Formatter::NumericFormatter
- Inherits:
-
Object
- Object
- Plurimath::Formatter::NumericFormatter
- Defined in:
- lib/plurimath/formatter/numeric_formatter.rb
Constant Summary collapse
- LOCALIZE_NUMBER_REGEX =
%r{(?<group>[^#])?(?<groupdigits>#+0)(?<decimal>.)(?<fractdigits>#+)(?<fractgroup>[^#])?}
- SUPPORTED_NOTATIONS =
%i[e scientific engineering].freeze
Instance Attribute Summary collapse
-
#locale ⇒ Object
Returns the value of attribute locale.
-
#localize_number ⇒ Object
writeonly
Sets the attribute localize_number.
-
#localizer_symbols ⇒ Object
Returns the value of attribute localizer_symbols.
Instance Method Summary collapse
-
#initialize(locale, localize_number:, localizer_symbols:) ⇒ NumericFormatter
constructor
A new instance of NumericFormatter.
- #localized_number(number_string, locale:, precision:, format:) ⇒ Object
Constructor Details
#initialize(locale, localize_number:, localizer_symbols:) ⇒ NumericFormatter
Returns a new instance of NumericFormatter.
16 17 18 19 20 21 |
# File 'lib/plurimath/formatter/numeric_formatter.rb', line 16 def initialize(locale, localize_number:, localizer_symbols:) @locale = locale @localize_number = localize_number @localizer_symbols = localizer_symbols @twitter_cldr_reader = twitter_cldr_reader end |
Instance Attribute Details
#locale ⇒ Object
Returns the value of attribute locale.
11 12 13 |
# File 'lib/plurimath/formatter/numeric_formatter.rb', line 11 def locale @locale end |
#localize_number=(value) ⇒ Object
Sets the attribute localize_number
11 12 13 |
# File 'lib/plurimath/formatter/numeric_formatter.rb', line 11 def localize_number=(value) @localize_number = value end |
#localizer_symbols ⇒ Object
Returns the value of attribute localizer_symbols.
11 12 13 |
# File 'lib/plurimath/formatter/numeric_formatter.rb', line 11 def localizer_symbols @localizer_symbols end |
Instance Method Details
#localized_number(number_string, locale:, precision:, format:) ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/plurimath/formatter/numeric_formatter.rb', line 23 def localized_number(number_string, locale:, precision:, format:) (number_string, format, precision) @twitter_cldr_reader.merge!(format) return send("#{@notation}_format", number_string) if SUPPORTED_NOTATIONS.include?(@notation&.to_sym) localize_number(number_string) end |