Class: Plurimath::Formatter::Numbers::FormatOptions
- Inherits:
-
Object
- Object
- Plurimath::Formatter::Numbers::FormatOptions
- 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
-
#exponent_separator ⇒ Object
readonly
Returns the value of attribute exponent_separator.
-
#exponent_sign ⇒ Object
readonly
Returns the value of attribute exponent_sign.
-
#notation ⇒ Object
readonly
Returns the value of attribute notation.
-
#precision ⇒ Object
readonly
Returns the value of attribute precision.
-
#symbols ⇒ Object
readonly
Returns the value of attribute symbols.
-
#times ⇒ Object
readonly
Returns the value of attribute times.
Instance Method Summary collapse
- #base ⇒ Object
- #base_postfix ⇒ Object
- #base_postfix? ⇒ Boolean
- #base_prefix ⇒ Object
- #base_prefix? ⇒ Boolean
- #decimal ⇒ Object
- #digit_count ⇒ Object
- #fraction_group ⇒ Object
- #fraction_group_digits ⇒ Object
- #group ⇒ Object
- #group_digits ⇒ Object
- #hex_capital ⇒ Object
-
#initialize(source = nil, symbols: {}, precision: nil, precision_resolver: nil) ⇒ FormatOptions
constructor
A new instance of FormatOptions.
- #notation_supported? ⇒ Boolean
- #number_sign ⇒ Object
- #padding ⇒ Object
- #padding_digits ⇒ Object
- #padding_group_digits ⇒ Object
- #significant ⇒ Object
- #to_h ⇒ Object
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) end |
Instance Attribute Details
#exponent_separator ⇒ Object (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_sign ⇒ Object (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 |
#notation ⇒ Object (readonly)
Returns the value of attribute notation.
16 17 18 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 16 def notation @notation end |
#precision ⇒ Object (readonly)
Returns the value of attribute precision.
16 17 18 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 16 def precision @precision end |
#symbols ⇒ Object (readonly)
Returns the value of attribute symbols.
16 17 18 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 16 def symbols @symbols end |
#times ⇒ Object (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
#base ⇒ Object
34 35 36 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 34 def base symbols[:base] || Base::DEFAULT_BASE end |
#base_postfix ⇒ Object
46 47 48 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 46 def base_postfix symbols[:base_postfix] end |
#base_postfix? ⇒ Boolean
50 51 52 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 50 def base_postfix? symbols.key?(:base_postfix) end |
#base_prefix ⇒ Object
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
42 43 44 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 42 def base_prefix? symbols.key?(:base_prefix) end |
#decimal ⇒ Object
54 55 56 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 54 def decimal symbols.fetch(:decimal, DEFAULT_DECIMAL) end |
#digit_count ⇒ Object
58 59 60 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 58 def digit_count symbols[:digit_count].to_i end |
#fraction_group ⇒ Object
62 63 64 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 62 def fraction_group symbols[:fraction_group].to_s end |
#fraction_group_digits ⇒ Object
66 67 68 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 66 def fraction_group_digits symbols[:fraction_group_digits] end |
#group ⇒ Object
70 71 72 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 70 def group symbols[:group] || DEFAULT_GROUP end |
#group_digits ⇒ Object
74 75 76 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 74 def group_digits symbols[:group_digits] || DEFAULT_GROUP_DIGITS end |
#hex_capital ⇒ Object
78 79 80 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 78 def hex_capital symbols[:hex_capital] end |
#notation_supported? ⇒ Boolean
99 100 101 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 99 def notation_supported? NotationRenderer.supported?(notation) end |
#number_sign ⇒ Object
82 83 84 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 82 def number_sign symbols[:number_sign] end |
#padding ⇒ Object
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_digits ⇒ Object
91 92 93 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 91 def padding_digits symbols[:padding_digits].to_i end |
#padding_group_digits ⇒ Object
95 96 97 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 95 def padding_group_digits symbols[:padding_group_digits].to_i end |
#significant ⇒ Object
103 104 105 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 103 def significant symbols[:significant].to_i end |
#to_h ⇒ Object
107 108 109 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 107 def to_h symbols.dup end |