Class: SQLTree::Node::LogicalExpression
- Inherits:
-
Expression
- Object
- Base
- Expression
- SQLTree::Node::LogicalExpression
- Defined in:
- lib/sql_tree/node/expression.rb
Instance Attribute Summary collapse
-
#expressions ⇒ Object
Returns the value of attribute expressions.
-
#operator ⇒ Object
Returns the value of attribute operator.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(operator, expressions) ⇒ LogicalExpression
constructor
A new instance of LogicalExpression.
- #to_sql ⇒ Object
Methods inherited from Expression
Methods inherited from Base
[], #inspect, #quote_str, #quote_var
Constructor Details
#initialize(operator, expressions) ⇒ LogicalExpression
Returns a new instance of LogicalExpression.
65 66 67 68 |
# File 'lib/sql_tree/node/expression.rb', line 65 def initialize(operator, expressions) @expressions = expressions @operator = operator.to_s.downcase.to_sym end |
Instance Attribute Details
#expressions ⇒ Object
Returns the value of attribute expressions.
63 64 65 |
# File 'lib/sql_tree/node/expression.rb', line 63 def expressions @expressions end |
#operator ⇒ Object
Returns the value of attribute operator.
63 64 65 |
# File 'lib/sql_tree/node/expression.rb', line 63 def operator @operator end |
Class Method Details
.parse(tokens) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/sql_tree/node/expression.rb', line 78 def self.parse(tokens) expr = ComparisonExpression.parse(tokens) while [SQLTree::Token::AND, SQLTree::Token::OR].include?(tokens.peek) expr = SQLTree::Node::LogicalExpression.new(tokens.next.literal, [expr, ComparisonExpression.parse(tokens)]) end return expr end |
Instance Method Details
#==(other) ⇒ Object
74 75 76 |
# File 'lib/sql_tree/node/expression.rb', line 74 def ==(other) self.operator == other.operator && self.expressions == other.expressions end |
#to_sql ⇒ Object
70 71 72 |
# File 'lib/sql_tree/node/expression.rb', line 70 def to_sql "(" + @expressions.map { |e| e.to_sql }.join(" #{@operator.to_s.upcase} ") + ")" end |