Module: Plurimath::BaseNumberPrefix::Transform

Included in:
Asciimath::Transform, Html::Transform, Latex::Transform, UnicodeMath::Transform
Defined in:
lib/plurimath/base_number_prefix.rb

Overview

Adds Parslet transform rules that build Math::Number with the correct base attribute from hex/binary/octal parse tree nodes. Include in any Parslet::Transform subclass.

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/plurimath/base_number_prefix.rb', line 34

def self.included(base)
  base.class_eval do
    rule(hex_number: simple(:hex)) { Math::Number.new(hex.to_s, base: 16) }
    rule(binary_number: simple(:bin)) { Math::Number.new(bin.to_s.to_i(2).to_s, base: 2) }
    rule(octal_number: simple(:oct)) { Math::Number.new(oct.to_s.to_i(8).to_s, base: 8) }
  end
end