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



16
17
18
# File 'lib/ffi-icu/number_formatting.rb', line 16

def self.clear_default_options
  @default_options.clear
end

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



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

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



32
33
34
# File 'lib/ffi-icu/number_formatting.rb', line 32

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

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



24
25
26
# File 'lib/ffi-icu/number_formatting.rb', line 24

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

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



28
29
30
# File 'lib/ffi-icu/number_formatting.rb', line 28

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

.set_default_options(options) ⇒ Object



20
21
22
# File 'lib/ffi-icu/number_formatting.rb', line 20

def self.set_default_options(options)
  @default_options.merge!(options)
end

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



36
37
38
# File 'lib/ffi-icu/number_formatting.rb', line 36

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