class TPPlus::Nodes::IOMethodNode
Public Class Methods
new(method, target,options={})
click to toggle source
# File lib/tp_plus/nodes/io_method_node.rb, line 4 def initialize(method, target,options={}) @method = method @target = target @init_options = options end
Public Instance Methods
can_be_inlined?()
click to toggle source
# File lib/tp_plus/nodes/io_method_node.rb, line 14 def can_be_inlined? true end
eval(context,options={})
click to toggle source
# 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={})
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# File lib/tp_plus/nodes/io_method_node.rb, line 10 def requires_mixed_logic?(context) true end