class NumRu::Units::NameNode
Constants
- CACHE
- UALIASES
- UDEFS
- UPLURALS
Public Class Methods
new(string)
click to toggle source
# File lib/numru/units.rb, line 679 def initialize(string) @a = string end
Public Instance Methods
basic?()
click to toggle source
# File lib/numru/units.rb, line 728 def basic? not (UDEFS.include?(@a) or UALIASES.include?(@a)) end
expand(stopper)
click to toggle source
# File lib/numru/units.rb, line 694 def expand(stopper) raise "circular dependency for #{@a}" if stopper[@a] return self if basic? return CACHE[@a] if CACHE.include?(@a) CACHE[@a] = expand2(stopper) end
expand2(stopper)
click to toggle source
# File lib/numru/units.rb, line 701 def expand2(stopper) newstopper = stopper.dup newstopper[@a] = true if UDEFS.include?(@a) then Units.new(UDEFS[@a]).ptree.expand(newstopper) else p, n = UALIASES[@a] u = Units.new(UDEFS[n] || n).ptree.expand(newstopper) MulNode.new(u, PowNode.new(NumberNode.new(10), NumberNode.new(p))) end end
factor()
click to toggle source
# File lib/numru/units.rb, line 734 def factor 1 end
foldnumber(stopper)
click to toggle source
# File lib/numru/units.rb, line 722 def foldnumber(stopper) return self unless UPLURALS.include?(@a) n = UPLURALS[@a] NameNode.new(n) end
mul_eval(another)
click to toggle source
# File lib/numru/units.rb, line 689 def mul_eval(another) raise "internal error (#{name}, #{another.name})" if name != another.name PowNode.new(self, self.power.add_eval(another.power)) end
power()
click to toggle source
# File lib/numru/units.rb, line 687 def power; NumberNode::UNITY; end
to_s()
click to toggle source
# File lib/numru/units.rb, line 683 def to_s; @a; end
Also aliased as: name
unalias(stopper)
click to toggle source
# File lib/numru/units.rb, line 713 def unalias(stopper) raise "circular dependency for #{@a}" if stopper[@a] return self unless UALIASES.include?(@a) p, n = UALIASES[@a] u = NameNode.new(n) q = PowNode.new(NumberNode.new(10), NumberNode.new(p)) MulNode.new(u, q) end