class NumRu::Units::NumberNode

Constants

UNITY
ZERO

Attributes

a[R]
factor[R]
value[R]

Public Class Methods

new(arg) click to toggle source
# File lib/numru/units.rb, line 2198
def initialize(arg)
    raise TypeError unless Numeric === arg
    @a = arg
end

Public Instance Methods

==(other) click to toggle source
# File lib/numru/units.rb, line 2219
def == (other)
  case other
  when NumberNode
    @a == other.a
  else
    false
  end
end
add_eval(another) click to toggle source
# File lib/numru/units.rb, line 2228
def add_eval(another)
    raise TypeError unless NumberNode === another
    NumberNode.new(@a + another.value)
end
mul_eval(another) click to toggle source
# File lib/numru/units.rb, line 2233
def mul_eval(another)
    case another
    when NumberNode then NumberNode.new(@a * another.a)
    when PowNode
        raise TypeError unless NumberNode === another.lhs
        raise TypeError unless NumberNode === another.rhs
        NumberNode.new(@a * Units::pow_f(another.lhs.value, another.rhs.value))
    else raise TypeError
    end
end
name() click to toggle source
# File lib/numru/units.rb, line 2244
def name; "1"; end
power() click to toggle source
# File lib/numru/units.rb, line 2246
def power;  UNITY;  end
to_s() click to toggle source
# File lib/numru/units.rb, line 2206
def to_s
  if @a == @a.to_i
    sprintf("%d",@a)
  else
    String(@a)
  end
end