Class: FormulaDSL::BinaryExpression

Inherits:
Object
  • Object
show all
Defined in:
lib/formula_dsl/binary_expression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(operator, left_term, right_term) ⇒ BinaryExpression

Returns a new instance of BinaryExpression.



7
8
9
10
11
# File 'lib/formula_dsl/binary_expression.rb', line 7

def initialize(operator, left_term, right_term)
  @operator = operator
  @left_term = left_term
  @right_term = right_term
end

Instance Attribute Details

#left_termObject (readonly)

Returns the value of attribute left_term.



5
6
7
# File 'lib/formula_dsl/binary_expression.rb', line 5

def left_term
  @left_term
end

#operatorObject (readonly)

Returns the value of attribute operator.



5
6
7
# File 'lib/formula_dsl/binary_expression.rb', line 5

def operator
  @operator
end

#right_termObject (readonly)

Returns the value of attribute right_term.



5
6
7
# File 'lib/formula_dsl/binary_expression.rb', line 5

def right_term
  @right_term
end

Instance Method Details

#==(other) ⇒ Object



21
22
23
# File 'lib/formula_dsl/binary_expression.rb', line 21

def == (other)
  @operator == other.operator && @left_term == other.left_term && @right_term == other.right_term
end

#applyObject



13
14
15
16
17
18
19
# File 'lib/formula_dsl/binary_expression.rb', line 13

def apply
  @left_term = @left_term.apply if @left_term.respond_to? :apply
  @right_term = @right_term.apply if @right_term.respond_to? :apply
  operation = BinaryExpressionFactory.new(@operator)

  operation.call(@left_term, @right_term)
end