Class: TPPlus::Nodes::IOMethodNode

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

Instance Method Summary collapse

Constructor Details

#initialize(method, target, options = {}) ⇒ IOMethodNode

Returns a new instance of IOMethodNode.



4
5
6
7
8
# File 'lib/tp_plus/nodes/io_method_node.rb', line 4

def initialize(method, target,options={})
  @method = method
  @target = target
  @init_options = options
end

Instance Method Details

#can_be_inlined?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/tp_plus/nodes/io_method_node.rb', line 14

def can_be_inlined?
  true
end

#eval(context, options = {}) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/tp_plus/nodes/io_method_node.rb', line 39

def eval(context,options={})
  options[:mixed_logic] = true if @target.requires_mixed_logic?(context)

  case @method
  when "turn_on"
    "#{@target.eval(context)}=#{on_off("ON",options)}"
  when "turn_off"
    "#{@target.eval(context)}=#{on_off("OFF",options)}"
  when "toggle"
    "#{@target.eval(context)}=(!#{@target.eval(context)})"
  when "pulse"
    "#{@target.eval(context)}=PULSE#{pulse_extra(context)}"
  end
end

#on_off(value, options = {}) ⇒ Object



18
19
20
# File 'lib/tp_plus/nodes/io_method_node.rb', line 18

def on_off(value,options={})
  options[:mixed_logic] ? "(#{value})" : value
end

#pulse_extra(context) ⇒ Object



33
34
35
36
37
# File 'lib/tp_plus/nodes/io_method_node.rb', line 33

def pulse_extra(context)
  return "" if @init_options[:pulse_time].nil?

  ",#{pulse_time(context)}sec"
end

#pulse_time(context) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/tp_plus/nodes/io_method_node.rb', line 22

def pulse_time(context)
  "%.1f" % case @init_options[:pulse_units]
  when "s"
    @init_options[:pulse_time].eval(context)
  when "ms"
    @init_options[:pulse_time].eval(context).to_f / 1000
  else
    raise "Invalid pulse units"
  end
end

#requires_mixed_logic?(context) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/tp_plus/nodes/io_method_node.rb', line 10

def requires_mixed_logic?(context)
  true
end