Class: Hotdog::Commands::Search::BinaryExpressionNode
- Inherits:
-
ExpressionNode
- Object
- ExpressionNode
- Hotdog::Commands::Search::BinaryExpressionNode
- Defined in:
- lib/hotdog/commands/search.rb
Instance Attribute Summary collapse
-
#left ⇒ Object
readonly
Returns the value of attribute left.
-
#right ⇒ Object
readonly
Returns the value of attribute right.
Instance Method Summary collapse
- #evaluate(environment) ⇒ Object
-
#initialize(op, left, right) ⇒ BinaryExpressionNode
constructor
A new instance of BinaryExpressionNode.
Constructor Details
#initialize(op, left, right) ⇒ BinaryExpressionNode
177 178 179 180 181 |
# File 'lib/hotdog/commands/search.rb', line 177 def initialize(op, left, right) @op = op @left = left @right = right end |
Instance Attribute Details
#left ⇒ Object (readonly)
Returns the value of attribute left.
175 176 177 |
# File 'lib/hotdog/commands/search.rb', line 175 def left @left end |
#right ⇒ Object (readonly)
Returns the value of attribute right.
175 176 177 |
# File 'lib/hotdog/commands/search.rb', line 175 def right @right end |
Instance Method Details
#evaluate(environment) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
# File 'lib/hotdog/commands/search.rb', line 182 def evaluate(environment) case @op when "&&", "&", /\Aand\z/i left_values = @left.evaluate(environment) if left_values.empty? [] else right_values = @right.evaluate(environment) (left_values & right_values) end when "||", "|", /\Aor\z/i left_values = @left.evaluate(environment) right_values = @right.evaluate(environment) (left_values | right_values).uniq else raise(SyntaxError.new("unknown binary operator: #{@op}")) end end |