Class: Plurimath::Formatter::Numbers::FormatOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/plurimath/formatter/numbers/format_options.rb

Overview

Per-render view of merged formatter symbols and resolved precision.

Constant Summary collapse

DEFAULT_EXPONENT_SEPARATOR =
:e
DEFAULT_DECIMAL =
"."
DEFAULT_FRACTION_PRECISION =
3
DEFAULT_GROUP =
","
DEFAULT_GROUP_DIGITS =
3
DEFAULT_PADDING =
"0"
DEFAULT_TIMES =
"\u{d7}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source = nil, symbols: {}, precision: nil, precision_resolver: nil) ⇒ FormatOptions

Returns a new instance of FormatOptions.



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

def initialize(
  source = nil,
  symbols: {},
  precision: nil,
  precision_resolver: nil
)
  @symbols = symbols.dup
  @notation = symbol_option(:notation)
  @exponent_separator = symbol_option(:e) || DEFAULT_EXPONENT_SEPARATOR
  @times = symbol_option(:times) || DEFAULT_TIMES
  @precision = resolve_precision(source, precision, precision_resolver)
  @exponent_sign = symbol_option(:exponent_sign)
  validate_padding_options!
end

Instance Attribute Details

#exponent_separatorObject (readonly)

Returns the value of attribute exponent_separator.



16
17
18
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 16

def exponent_separator
  @exponent_separator
end

#exponent_signObject (readonly)

Returns the value of attribute exponent_sign.



16
17
18
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 16

def exponent_sign
  @exponent_sign
end

#notationObject (readonly)

Returns the value of attribute notation.



16
17
18
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 16

def notation
  @notation
end

#precisionObject (readonly)

Returns the value of attribute precision.



16
17
18
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 16

def precision
  @precision
end

#symbolsObject (readonly)

Returns the value of attribute symbols.



16
17
18
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 16

def symbols
  @symbols
end

#timesObject (readonly)

Returns the value of attribute times.



16
17
18
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 16

def times
  @times
end

Instance Method Details

#baseObject



34
35
36
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 34

def base
  symbols[:base] || Base::DEFAULT_BASE
end

#base_postfixObject



46
47
48
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 46

def base_postfix
  symbols[:base_postfix]
end

#base_postfix?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 50

def base_postfix?
  symbols.key?(:base_postfix)
end

#base_prefixObject



38
39
40
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 38

def base_prefix
  symbols[:base_prefix].to_s
end

#base_prefix?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 42

def base_prefix?
  symbols.key?(:base_prefix)
end

#decimalObject



54
55
56
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 54

def decimal
  symbols.fetch(:decimal, DEFAULT_DECIMAL)
end

#digit_countObject



58
59
60
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 58

def digit_count
  symbols[:digit_count].to_i
end

#fraction_groupObject



62
63
64
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 62

def fraction_group
  symbols[:fraction_group].to_s
end

#fraction_group_digitsObject



66
67
68
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 66

def fraction_group_digits
  symbols[:fraction_group_digits]
end

#groupObject



70
71
72
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 70

def group
  symbols[:group] || DEFAULT_GROUP
end

#group_digitsObject



74
75
76
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 74

def group_digits
  symbols[:group_digits] || DEFAULT_GROUP_DIGITS
end

#hex_capitalObject



78
79
80
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 78

def hex_capital
  symbols[:hex_capital]
end

#notation_supported?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 99

def notation_supported?
  NotationRenderer.supported?(notation)
end

#number_signObject



82
83
84
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 82

def number_sign
  symbols[:number_sign]
end

#paddingObject



86
87
88
89
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 86

def padding
  value = symbols.fetch(:padding, DEFAULT_PADDING).to_s
  value.empty? ? DEFAULT_PADDING : value[0]
end

#padding_digitsObject



91
92
93
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 91

def padding_digits
  symbols[:padding_digits].to_i
end

#padding_group_digitsObject



95
96
97
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 95

def padding_group_digits
  symbols[:padding_group_digits].to_i
end

#significantObject



103
104
105
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 103

def significant
  symbols[:significant].to_i
end

#to_hObject



107
108
109
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 107

def to_h
  symbols.dup
end