Class: Plurimath::Formatter::Numbers::BaseNotation
- Inherits:
-
Object
- Object
- Plurimath::Formatter::Numbers::BaseNotation
- Defined in:
- lib/plurimath/formatter/numbers/base_notation.rb
Overview
Describes base prefix/postfix notation as a resolved value object. Constructed from FormatOptions via .from_options; carries the resolved prefix and postfix strings so renderers can decide how to represent the base (inline text, MathML subscript, LaTeX subscript, etc.).
Constant Summary collapse
- DEFAULT_PREFIXES =
{ 2 => "0b", 8 => "0o", 10 => "", 16 => "0x", }.freeze
Instance Attribute Summary collapse
-
#base ⇒ Object
readonly
Returns the value of attribute base.
-
#hex_capital ⇒ Object
readonly
Returns the value of attribute hex_capital.
-
#postfix ⇒ Object
readonly
Returns the value of attribute postfix.
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Class Method Summary collapse
Instance Method Summary collapse
- #default? ⇒ Boolean
-
#initialize(base:, prefix: "", postfix: "", hex_capital: nil, explicit_prefix: false, explicit_postfix: false) ⇒ BaseNotation
constructor
A new instance of BaseNotation.
-
#literal? ⇒ Boolean
Caller overrode prefix or postfix at format-call time.
- #semantic? ⇒ Boolean
- #upcase_hex? ⇒ Boolean
- #wrap(digits) ⇒ Object
Constructor Details
#initialize(base:, prefix: "", postfix: "", hex_capital: nil, explicit_prefix: false, explicit_postfix: false) ⇒ BaseNotation
Returns a new instance of BaseNotation.
20 21 22 23 24 25 26 27 28 |
# File 'lib/plurimath/formatter/numbers/base_notation.rb', line 20 def initialize(base:, prefix: "", postfix: "", hex_capital: nil, explicit_prefix: false, explicit_postfix: false) @base = base @prefix = prefix @postfix = postfix @hex_capital = hex_capital @explicit_prefix = explicit_prefix @explicit_postfix = explicit_postfix end |
Instance Attribute Details
#base ⇒ Object (readonly)
Returns the value of attribute base.
18 19 20 |
# File 'lib/plurimath/formatter/numbers/base_notation.rb', line 18 def base @base end |
#hex_capital ⇒ Object (readonly)
Returns the value of attribute hex_capital.
18 19 20 |
# File 'lib/plurimath/formatter/numbers/base_notation.rb', line 18 def hex_capital @hex_capital end |
#postfix ⇒ Object (readonly)
Returns the value of attribute postfix.
18 19 20 |
# File 'lib/plurimath/formatter/numbers/base_notation.rb', line 18 def postfix @postfix end |
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
18 19 20 |
# File 'lib/plurimath/formatter/numbers/base_notation.rb', line 18 def prefix @prefix end |
Class Method Details
.from_options(options) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/plurimath/formatter/numbers/base_notation.rb', line 30 def self.() base = .base validate!(base) new( base: base, prefix: resolve_prefix(, base), postfix: .base_postfix.to_s, hex_capital: .hex_capital, explicit_prefix: .base_prefix?, explicit_postfix: .base_postfix?, ) end |
.supported?(base) ⇒ Boolean
44 45 46 |
# File 'lib/plurimath/formatter/numbers/base_notation.rb', line 44 def self.supported?(base) DEFAULT_PREFIXES.key?(base) end |
Instance Method Details
#default? ⇒ Boolean
48 49 50 |
# File 'lib/plurimath/formatter/numbers/base_notation.rb', line 48 def default? base == Base::DEFAULT_BASE end |
#literal? ⇒ Boolean
Caller overrode prefix or postfix at format-call time. Renderers that honor semantic base notation (msub, mathrm{}_#base, _(base)) must defer to the literal prefix/postfix in that case.
55 56 57 |
# File 'lib/plurimath/formatter/numbers/base_notation.rb', line 55 def literal? !default? && (explicit_prefix? || explicit_postfix?) end |
#semantic? ⇒ Boolean
59 60 61 |
# File 'lib/plurimath/formatter/numbers/base_notation.rb', line 59 def semantic? !default? && !literal? end |
#upcase_hex? ⇒ Boolean
63 64 65 |
# File 'lib/plurimath/formatter/numbers/base_notation.rb', line 63 def upcase_hex? base == 16 && hex_capital == true end |
#wrap(digits) ⇒ Object
67 68 69 |
# File 'lib/plurimath/formatter/numbers/base_notation.rb', line 67 def wrap(digits) "#{prefix}#{digits}#{postfix}" end |