class TPPlus::Nodes::WaitForNode
Public Class Methods
new(time, units)
click to toggle source
# File lib/tp_plus/nodes/wait_for_node.rb, line 4 def initialize(time, units) @time = time @units = units end
Public Instance Methods
eval(context)
click to toggle source
# File lib/tp_plus/nodes/wait_for_node.rb, line 50 def eval(context) raise "Invalid units" unless units_valid? "WAIT #{time(context)}" end
expression()
click to toggle source
# File lib/tp_plus/nodes/wait_for_node.rb, line 39 def expression case @units when "s" @time when "ms" e = ExpressionNode.new(@time,"/",DigitNode.new(1000)) e.grouped = true e end end
time(context)
click to toggle source
2 decimal places and remove leading 0s
# File lib/tp_plus/nodes/wait_for_node.rb, line 14 def time(context) case @time when DigitNode, RealNode case @units when "s" return ("%.2f(sec)" % @time.eval(context)).sub(/^0+/, "") when "ms" return ("%.2f(sec)" % (@time.eval(context).to_f / 1000)).sub(/^0+/, "") end when VarNode case @units when "s" if @time.constant? return ("%.2f(sec)" % @time.eval(context)).sub(/^0+/, "") else return @time.eval(context) end else raise "Indirect values can only use seconds ('s') as the units argument" end else raise "PANIC" end end
units_valid?()
click to toggle source
# File lib/tp_plus/nodes/wait_for_node.rb, line 9 def units_valid? ["s","ms"].include?(@units) end