class NumRu::Units::MultiNode
Attributes
children[R]
Public Class Methods
new(*children)
click to toggle source
# File lib/numru/units.rb, line 2553 def initialize(*children) @children = children for c in @children raise "# MultiNode.new(#{children.inspect})" unless Node === c end end
Public Instance Methods
append(other)
click to toggle source
# File lib/numru/units.rb, line 2571 def append(other) case other when MultiNode @children += other.children else @children.push other end end
collect_hash(stopper, op)
click to toggle source
# File lib/numru/units.rb, line 2607 def collect_hash(stopper, op) list = [] for child in self list.push(child.send(op, stopper)) end self.class.new(*list).flatten2 end
each() { |child| ... }
click to toggle source
# File lib/numru/units.rb, line 2565 def each @children.each {|child| yield child } end
expand(stopper)
click to toggle source
# File lib/numru/units.rb, line 2615 def expand(stopper) collect_hash(stopper, :expand) end
foldnumber(stopper)
click to toggle source
# File lib/numru/units.rb, line 2623 def foldnumber(stopper) collect_hash(stopper, :foldnumber) end
sort()
click to toggle source
# File lib/numru/units.rb, line 2580 def sort table = {} for child in self name = child.name if (table.include?(name)) then table[name] = table[name].mul_eval(child) else table[name] = child end end list = [] for name in table.keys.sort candi = table[name] if PowNode === candi and NumberNode === candi.lhs then v = candi.value list.push NumberNode.new(v) unless v == 1 next end next if candi.power.value == 0 list.push candi end if list.length > 1 list.delete(NumberNode::UNITY) end self.class.new(*list) end
to_s()
click to toggle source
# File lib/numru/units.rb, line 2560 def to_s s = @children.join(';') s.gsub(/\d;\w/) { |dsw| dsw.sub(/;/, ' ') }.gsub(/;/, '.') end
unalias(stopper)
click to toggle source
# File lib/numru/units.rb, line 2619 def unalias(stopper) collect_hash(stopper, :unalias) end
value()
click to toggle source
# File lib/numru/units.rb, line 2627 def value raise "this is dimensional units" if (@children.size > 1) @children.first ? @children.first.value : NumberNode::UNITY.value end