Class: Plurimath::Formatter::Standard

Inherits:
NumberFormatter show all
Defined in:
lib/plurimath/formatter/standard.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  fraction_group_digits: 3,
  exponent_sign: "plus",
  fraction_group: "'",
  number_sign: "plus",
  notation: :basic,
  group_digits: 3,
  significant: 0,
  digit_count: 0,
  precision: 0,
  decimal: ".",
  group: ",",
  times: "x",
  e: "e",
}.freeze

Instance Attribute Summary collapse

Attributes inherited from NumberFormatter

#locale, #localize_number, #localizer_symbols

Instance Method Summary collapse

Methods inherited from NumberFormatter

#localized_number, #twitter_cldr_reader

Constructor Details

#initialize(locale: "en", string_format: nil, options: {}, precision: nil) ⇒ Standard

Returns a new instance of Standard.



25
26
27
28
29
30
31
32
# File 'lib/plurimath/formatter/standard.rb', line 25

def initialize(locale: "en", string_format: nil, options: {}, precision: nil)
  super(
    locale,
    localize_number: string_format,
    localizer_symbols: set_default_options(options),
    precision: precision,
  )
end

Instance Attribute Details

#precisionObject

Returns the value of attribute precision.



7
8
9
# File 'lib/plurimath/formatter/standard.rb', line 7

def precision
  @precision
end

Instance Method Details

#set_default_options(options) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/plurimath/formatter/standard.rb', line 34

def set_default_options(options)
  default_options = self.class::DEFAULT_OPTIONS
  self.precision ||= default_options[:precision]
  options ||= default_options
  options[:fraction_group_digits] ||= default_options[:fraction_group_digits]
  options[:fraction_group] ||= default_options[:fraction_group]
  options[:exponent_sign] ||= default_options[:exponent_sign]
  options[:group_digits] ||= default_options[:group_digits]
  options[:number_sign] ||= default_options[:number_sign]
  options[:significant] ||= default_options[:significant]
  options[:notation] ||= default_options[:notation]
  options[:decimal] ||= default_options[:decimal]
  options[:group] ||= default_options[:group]
  options[:times] ||= default_options[:times]
  options[:e] ||= default_options[:e]
  options
end