Class: TPPlus::Nodes::WaitForNode
- Defined in:
- lib/tp_plus/nodes/wait_for_node.rb
Instance Method Summary collapse
- #eval(context) ⇒ Object
- #expression ⇒ Object
-
#initialize(time, units) ⇒ WaitForNode
constructor
A new instance of WaitForNode.
-
#time(context) ⇒ Object
2 decimal places and remove leading 0s.
- #units_valid? ⇒ Boolean
Methods inherited from BaseNode
Constructor Details
#initialize(time, units) ⇒ WaitForNode
Returns a new instance of WaitForNode.
4 5 6 7 |
# File 'lib/tp_plus/nodes/wait_for_node.rb', line 4 def initialize(time, units) @time = time @units = units end |
Instance Method Details
#eval(context) ⇒ Object
50 51 52 53 54 |
# 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 ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# 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) ⇒ Object
2 decimal places and remove leading 0s
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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? ⇒ Boolean
9 10 11 |
# File 'lib/tp_plus/nodes/wait_for_node.rb', line 9 def units_valid? ["s","ms"].include?(@units) end |