Class: Plurimath::NumberFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/plurimath/number_formatter.rb

Direct Known Subclasses

Formatter::Standard

Instance Attribute Summary collapse

Instance Method Summary collapse

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
13
14
15
16
17
# 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

#localeObject

Returns the value of attribute locale.



5
6
7
# File 'lib/plurimath/number_formatter.rb', line 5

def locale
  @locale
end

#localize_numberObject

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_symbolsObject

Returns the value of attribute localizer_symbols.



5
6
7
# File 'lib/plurimath/number_formatter.rb', line 5

def localizer_symbols
  @localizer_symbols
end

#precisionObject

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



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/plurimath/number_formatter.rb', line 19

def localized_number(
  number_string,
  locale: @locale,
  precision: @precision,
  format: {}
)
  locale = supported_locale(locale)
  source = Formatter::Numbers::Source.new(number_string)
  options = format_options(source, locale, precision, format)

  if options.notation_supported?
    return notation_renderer(options).render(source, options.notation)
  end

  render_localized_number(source, options)
end

#twitter_cldr_reader(locale: @locale) ⇒ Object



36
37
38
# File 'lib/plurimath/number_formatter.rb', line 36

def twitter_cldr_reader(locale: @locale)
  symbols_for(supported_locale(locale), {})
end