Class: Plurimath::Formatter::Numbers::FormattedNotation
- Inherits:
-
Object
- Object
- Plurimath::Formatter::Numbers::FormattedNotation
- Defined in:
- lib/plurimath/formatter/numbers/formatted_notation.rb
Overview
Structured result of notation formatting (e, scientific, engineering). Carries the coefficient as a FormattedNumber, the exponent as an integer, and notation style metadata so output renderers (MathML, LaTeX, etc.) can produce structured representations instead of flat strings.
Constant Summary collapse
- STYLES =
%i[e scientific engineering].freeze
Instance Attribute Summary collapse
-
#coefficient ⇒ Object
readonly
Returns the value of attribute coefficient.
-
#exponent ⇒ Object
readonly
Returns the value of attribute exponent.
-
#exponent_separator ⇒ Object
readonly
Returns the value of attribute exponent_separator.
-
#exponent_sign ⇒ Object
readonly
Returns the value of attribute exponent_sign.
-
#notation_style ⇒ Object
readonly
Returns the value of attribute notation_style.
-
#times_symbol ⇒ Object
readonly
Returns the value of attribute times_symbol.
Instance Method Summary collapse
- #base_notation? ⇒ Boolean
-
#formatted_exponent ⇒ Object
The exponent rendered as a string, applying sign conventions.
-
#initialize(coefficient:, notation_style:, exponent:, times_symbol: "×", exponent_separator: "e", exponent_sign: nil) ⇒ FormattedNotation
constructor
A new instance of FormattedNotation.
- #to_s ⇒ Object
- #to_str ⇒ Object
Constructor Details
#initialize(coefficient:, notation_style:, exponent:, times_symbol: "×", exponent_separator: "e", exponent_sign: nil) ⇒ FormattedNotation
Returns a new instance of FormattedNotation.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/plurimath/formatter/numbers/formatted_notation.rb', line 17 def initialize( coefficient:, notation_style:, exponent:, times_symbol: "×", exponent_separator: "e", exponent_sign: nil ) @coefficient = coefficient @notation_style = notation_style @exponent = exponent @times_symbol = times_symbol @exponent_separator = exponent_separator @exponent_sign = exponent_sign end |
Instance Attribute Details
#coefficient ⇒ Object (readonly)
Returns the value of attribute coefficient.
14 15 16 |
# File 'lib/plurimath/formatter/numbers/formatted_notation.rb', line 14 def coefficient @coefficient end |
#exponent ⇒ Object (readonly)
Returns the value of attribute exponent.
14 15 16 |
# File 'lib/plurimath/formatter/numbers/formatted_notation.rb', line 14 def exponent @exponent end |
#exponent_separator ⇒ Object (readonly)
Returns the value of attribute exponent_separator.
14 15 16 |
# File 'lib/plurimath/formatter/numbers/formatted_notation.rb', line 14 def exponent_separator @exponent_separator end |
#exponent_sign ⇒ Object (readonly)
Returns the value of attribute exponent_sign.
14 15 16 |
# File 'lib/plurimath/formatter/numbers/formatted_notation.rb', line 14 def exponent_sign @exponent_sign end |
#notation_style ⇒ Object (readonly)
Returns the value of attribute notation_style.
14 15 16 |
# File 'lib/plurimath/formatter/numbers/formatted_notation.rb', line 14 def notation_style @notation_style end |
#times_symbol ⇒ Object (readonly)
Returns the value of attribute times_symbol.
14 15 16 |
# File 'lib/plurimath/formatter/numbers/formatted_notation.rb', line 14 def times_symbol @times_symbol end |
Instance Method Details
#base_notation? ⇒ Boolean
46 47 48 |
# File 'lib/plurimath/formatter/numbers/formatted_notation.rb', line 46 def base_notation? coefficient.base_notation? end |
#formatted_exponent ⇒ Object
The exponent rendered as a string, applying sign conventions. Public so that output renderers can access it directly.
52 53 54 55 56 57 58 |
# File 'lib/plurimath/formatter/numbers/formatted_notation.rb', line 52 def formatted_exponent return "0" if exponent.zero? sign_prefix = exponent_sign == :plus ? "+" : nil abs_exp = exponent.abs.to_s exponent.negative? ? "-#{abs_exp}" : "#{sign_prefix}#{abs_exp}" end |
#to_s ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/plurimath/formatter/numbers/formatted_notation.rb', line 33 def to_s case notation_style when :e "#{coefficient}#{exponent_separator}#{formatted_exponent}" when :scientific, :engineering "#{coefficient} #{times_symbol} 10^#{formatted_exponent}" end end |
#to_str ⇒ Object
42 43 44 |
# File 'lib/plurimath/formatter/numbers/formatted_notation.rb', line 42 def to_str to_s end |