Class: Plurimath::Formatter::Numbers::NotationRenderer

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

Overview

Builds e/scientific/engineering notation while delegating coefficient localization back through the structured renderer.

Constant Summary collapse

SUPPORTED_NOTATIONS =
%i[e scientific engineering].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ NotationRenderer

Returns a new instance of NotationRenderer.



11
12
13
14
15
# File 'lib/plurimath/formatter/numbers/notation_renderer.rb', line 11

def initialize(options)
  @options = options
  @precision = (@options.precision || 0).to_i
  @exponent_sign_renderer = SignRenderer.new(@options.exponent_sign)
end

Class Method Details

.supported?(notation) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/plurimath/formatter/numbers/notation_renderer.rb', line 28

def self.supported?(notation)
  SUPPORTED_NOTATIONS.include?(notation&.to_sym)
end

Instance Method Details

#render(source, notation) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/plurimath/formatter/numbers/notation_renderer.rb', line 17

def render(source, notation)
  case notation.to_sym
  when :e
    render_e(source)
  when :scientific
    render_scientific(source)
  when :engineering
    render_engineering(source)
  end
end