Class: TPPlus::Nodes::IOMethodNode
- Defined in:
- lib/tp_plus/nodes/io_method_node.rb
Instance Method Summary collapse
- #can_be_inlined? ⇒ Boolean
- #eval(context, options = {}) ⇒ Object
-
#initialize(method, target, options = {}) ⇒ IOMethodNode
constructor
A new instance of IOMethodNode.
- #on_off(value, options = {}) ⇒ Object
- #pulse_extra(context) ⇒ Object
- #pulse_time(context) ⇒ Object
- #requires_mixed_logic?(context) ⇒ Boolean
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,={}) @method = method @target = target @init_options = end |
Instance Method Details
#can_be_inlined? ⇒ 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,={}) [:mixed_logic] = true if @target.requires_mixed_logic?(context) case @method when "turn_on" "#{@target.eval(context)}=#{on_off("ON",)}" when "turn_off" "#{@target.eval(context)}=#{on_off("OFF",)}" 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,={}) [: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
10 11 12 |
# File 'lib/tp_plus/nodes/io_method_node.rb', line 10 def requires_mixed_logic?(context) true end |