Module: ICU::NumberFormatting

Defined in:
lib/ffi-icu/number_formatting.rb

Defined Under Namespace

Classes: BaseFormatter, CurrencyFormatter, NumberFormatter

Class Method Summary collapse

Class Method Details

.clear_default_optionsObject



18
19
20
# File 'lib/ffi-icu/number_formatting.rb', line 18

def self.clear_default_options
  @default_options.clear
end

.create(locale, type = :decimal, options = {}) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/ffi-icu/number_formatting.rb', line 9

def self.create(locale, type = :decimal, options = {})
  case type
  when :currency
    CurrencyFormatter.new(locale, options.delete(:style)).set_attributes(@default_options.merge(options))
  else
    NumberFormatter.new(locale, type).set_attributes(@default_options.merge(options))
  end
end

.format_currency(locale, number, currency, options = {}) ⇒ Object



34
35
36
# File 'lib/ffi-icu/number_formatting.rb', line 34

def self.format_currency(locale, number, currency, options = {})
  create(locale, :currency, options).format(number, currency)
end

.format_number(locale, number, options = {}) ⇒ Object



26
27
28
# File 'lib/ffi-icu/number_formatting.rb', line 26

def self.format_number(locale, number, options = {})
  create(locale, :decimal, options).format(number)
end

.format_percent(locale, number, options = {}) ⇒ Object



30
31
32
# File 'lib/ffi-icu/number_formatting.rb', line 30

def self.format_percent(locale, number, options = {})
  create(locale, :percent, options).format(number)
end

.set_default_options(options) ⇒ Object

rubocop:disable Naming/AccessorMethodName



22
23
24
# File 'lib/ffi-icu/number_formatting.rb', line 22

def self.set_default_options(options) # rubocop:disable Naming/AccessorMethodName
  @default_options.merge!(options)
end

.spell(locale, number, options = {}) ⇒ Object



38
39
40
# File 'lib/ffi-icu/number_formatting.rb', line 38

def self.spell(locale, number, options = {})
  create(locale, :spellout, options).format(number)
end