Class: Foxtail::Function::Number
- Defined in:
- lib/foxtail/function/number.rb
Overview
Wraps a numeric value with formatting options The raw value is preserved for selector matching (plural rules)
Instance Attribute Summary
Attributes inherited from Value
Class Method Summary collapse
-
.convert_options(options) ⇒ Hash
Convert FTL/JS style number options to ICU4X options.
Instance Method Summary collapse
-
#format(bundle:) ⇒ String
Format the number using ICU4X.
Methods inherited from Value
Class Method Details
.convert_options(options) ⇒ Hash
Convert FTL/JS style number options to ICU4X options
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/foxtail/function/number.rb', line 11 def self.() result = {} .each do |key, value| case key when :style result[:style] = value.to_sym when :currency result[:currency] = value.to_s when :minimumIntegerDigits result[:minimum_integer_digits] = Integer(value) when :minimumFractionDigits result[:minimum_fraction_digits] = Integer(value) when :maximumFractionDigits result[:maximum_fraction_digits] = Integer(value) when :useGrouping result[:use_grouping] = value else warn "Unknown NUMBER option: #{key}" end end result end |
Instance Method Details
#format(bundle:) ⇒ String
Format the number using ICU4X
39 40 41 42 |
# File 'lib/foxtail/function/number.rb', line 39 def format(bundle:) = self.class.() ICU4XCache.instance.number_formatter(bundle.locale, **).format(value) end |