Class: TPPlus::Nodes::OperatorNode
- Defined in:
- lib/tp_plus/nodes/operator_node.rb
Instance Attribute Summary collapse
-
#string ⇒ Object
readonly
Returns the value of attribute string.
Instance Method Summary collapse
- #bang? ⇒ Boolean
- #boolean? ⇒ Boolean
- #eval(context, options = {}) ⇒ Object
-
#initialize(string) ⇒ OperatorNode
constructor
A new instance of OperatorNode.
- #requires_mixed_logic?(context) ⇒ Boolean
Methods inherited from BaseNode
Constructor Details
#initialize(string) ⇒ OperatorNode
Returns a new instance of OperatorNode.
5 6 7 |
# File 'lib/tp_plus/nodes/operator_node.rb', line 5 def initialize(string) @string = string end |
Instance Attribute Details
#string ⇒ Object (readonly)
Returns the value of attribute string.
4 5 6 |
# File 'lib/tp_plus/nodes/operator_node.rb', line 4 def string @string end |
Instance Method Details
#bang? ⇒ Boolean
9 10 11 |
# File 'lib/tp_plus/nodes/operator_node.rb', line 9 def bang? @string == "!" end |
#boolean? ⇒ Boolean
22 23 24 25 26 27 28 29 |
# File 'lib/tp_plus/nodes/operator_node.rb', line 22 def boolean? case @string when "&&", "||", "!"#, "==", "<>", ">", ">=", "<", "<=" true else false end end |
#eval(context, options = {}) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/tp_plus/nodes/operator_node.rb', line 31 def eval(context,={}) if [:opposite] case @string when "==" "<>" when "!=", "<>" "=" when ">" "<=" when "<" ">=" when ">=" "<" when "<=" ">" when "!" "" when "||" " AND " when "&&" " OR " when "DIV" " MOD " else "#{@string}" end else case @string when "==" "=" when "!=" "<>" when "&&" " AND " when "||" " OR " when "%" " MOD " when "DIV" " DIV " else "#{@string}" end end end |
#requires_mixed_logic?(context) ⇒ Boolean
13 14 15 16 17 18 19 20 |
# File 'lib/tp_plus/nodes/operator_node.rb', line 13 def requires_mixed_logic?(context) case @string when "&&", "||", "!" true else false end end |