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
-
#explicit_precision? ⇒ Boolean
Whether precision came from the caller (kwarg or symbols) rather than being inferred from the source by the resolver.
- #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 37 38 39 40 41 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 34 def base value = symbols[:base] return Base::DEFAULT_BASE if value.nil? # Numeric String/Symbol forms are normalized; anything else is left # raw so BaseNotation reports it through UnsupportedBase. coerce_integer(value) { return value } end |
#base_postfix ⇒ Object
51 52 53 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 51 def base_postfix separator_option(:base_postfix) end |
#base_postfix? ⇒ Boolean
55 56 57 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 55 def base_postfix? symbols.key?(:base_postfix) end |
#base_prefix ⇒ Object
43 44 45 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 43 def base_prefix separator_option(:base_prefix).to_s end |
#base_prefix? ⇒ Boolean
47 48 49 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 47 def base_prefix? symbols.key?(:base_prefix) end |
#decimal ⇒ Object
59 60 61 62 63 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 59 def decimal # An explicitly passed nil renders without a separator; output # correctness is then the caller's responsibility. separator_option(:decimal, default: DEFAULT_DECIMAL) end |
#digit_count ⇒ Object
65 66 67 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 65 def digit_count integer_option(:digit_count, default: 0) end |
#explicit_precision? ⇒ Boolean
Whether precision came from the caller (kwarg or symbols) rather than being inferred from the source by the resolver.
132 133 134 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 132 def explicit_precision? @explicit_precision end |
#fraction_group ⇒ Object
69 70 71 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 69 def fraction_group separator_option(:fraction_group).to_s end |
#fraction_group_digits ⇒ Object
73 74 75 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 73 def fraction_group_digits integer_option(:fraction_group_digits) end |
#group ⇒ Object
77 78 79 80 81 82 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 77 def group # Unlike decimal, an explicit nil group falls back to the default # separator; use "" to disable grouping. (separator_option(:group, default: DEFAULT_GROUP) || DEFAULT_GROUP).to_s end |
#group_digits ⇒ Object
84 85 86 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 84 def group_digits integer_option(:group_digits, default: DEFAULT_GROUP_DIGITS) end |
#hex_capital ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 88 def hex_capital value = symbols[:hex_capital] # nil is handled first: under Opal `when nil` spuriously matches # non-nil values (nil === 1.5 is true there), so it must not appear # in the type whitelist below. return if value.nil? # Accept only Boolean/String/Symbol and reject any other type. # Attribute-parsing callers deliver String/Symbol (:true, # "numbers_only"), so the accepted forms normalize through to_s. case value when true, false, String, Symbol case value.to_s when "true" then true when "numbers_only" then :numbers_only end else invalid_option!(:hex_capital, value) end end |
#notation_supported? ⇒ Boolean
126 127 128 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 126 def notation_supported? NotationRenderer.supported?(notation) end |
#number_sign ⇒ Object
109 110 111 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 109 def number_sign symbol_option(:number_sign) end |
#padding ⇒ Object
113 114 115 116 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 113 def padding value = separator_option(:padding, default: DEFAULT_PADDING).to_s value.empty? ? DEFAULT_PADDING : value[0] end |
#padding_digits ⇒ Object
118 119 120 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 118 def padding_digits integer_option(:padding_digits, default: 0) end |
#padding_group_digits ⇒ Object
122 123 124 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 122 def padding_group_digits integer_option(:padding_group_digits, default: 0) end |
#significant ⇒ Object
136 137 138 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 136 def significant integer_option(:significant, default: 0) end |
#to_h ⇒ Object
140 141 142 |
# File 'lib/plurimath/formatter/numbers/format_options.rb', line 140 def to_h symbols.dup end |