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.
-
#twitter_cldr_reader ⇒ Object
Returns the value of attribute twitter_cldr_reader.
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.
11 12 13 14 15 16 |
# File 'lib/plurimath/formatter/numeric_formatter.rb', line 11 def initialize(locale, localize_number:, localizer_symbols:) @locale = locale @localize_number = localize_number @localizer_symbols = localizer_symbols @twitter_cldr_reader = twitter_cldr_reader_lookup end |
Instance Attribute Details
#locale ⇒ Object
Returns the value of attribute locale.
6 7 8 |
# File 'lib/plurimath/formatter/numeric_formatter.rb', line 6 def locale @locale end |
#localize_number=(value) ⇒ Object
Sets the attribute localize_number
6 7 8 |
# File 'lib/plurimath/formatter/numeric_formatter.rb', line 6 def localize_number=(value) @localize_number = value end |
#localizer_symbols ⇒ Object
Returns the value of attribute localizer_symbols.
6 7 8 |
# File 'lib/plurimath/formatter/numeric_formatter.rb', line 6 def localizer_symbols @localizer_symbols end |
#twitter_cldr_reader ⇒ Object
Returns the value of attribute twitter_cldr_reader.
6 7 8 |
# File 'lib/plurimath/formatter/numeric_formatter.rb', line 6 def twitter_cldr_reader @twitter_cldr_reader end |
Instance Method Details
#localized_number(number_string, locale:, precision:, format:) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/plurimath/formatter/numeric_formatter.rb', line 18 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 |