Class: TPPlus::Nodes::WaitForNode

Inherits:
Object
  • Object
show all
Defined in:
lib/tp_plus/nodes/wait_for_node.rb

Instance Method Summary collapse

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

#can_be_inlined?Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/tp_plus/nodes/wait_for_node.rb', line 32

def can_be_inlined?
  false
end

#eval(context) ⇒ Object



47
48
49
50
51
# File 'lib/tp_plus/nodes/wait_for_node.rb', line 47

def eval(context)
  raise "Invalid units" unless units_valid?

  "WAIT #{time(context)}"
end

#expressionObject



36
37
38
39
40
41
42
43
44
45
# File 'lib/tp_plus/nodes/wait_for_node.rb', line 36

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
# File 'lib/tp_plus/nodes/wait_for_node.rb', line 14

def time(context)
  if @time.eval(context).is_a?(String)
    case @units
    when "s"
      @time.eval(context)
    else
      raise "Invalid units"
    end
  else
    ("%.2f" % case @units
    when "s"
      @time.eval(context)
    when "ms"
      @time.eval(context).to_f / 1000
    end).sub(/^0+/, "") + "(sec)"
  end
end

#units_valid?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/tp_plus/nodes/wait_for_node.rb', line 9

def units_valid?
  ["s","ms"].include?(@units)
end