Class: Flounder::Expression::BinaryOp

Inherits:
Expr
  • Object
show all
Defined in:
lib/flounder/expression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Expr

#&, #as, #cast, #db_quote, #eval, #to_immediate, #|

Constructor Details

#initialize(domain, op_string, *terms) ⇒ BinaryOp

Returns a new instance of BinaryOp.



107
108
109
110
111
112
# File 'lib/flounder/expression.rb', line 107

def initialize domain, op_string, *terms
  super(domain)

  @op_string = op_string
  @terms = terms
end

Instance Attribute Details

#op_stringObject

Returns the value of attribute op_string.



114
115
116
# File 'lib/flounder/expression.rb', line 114

def op_string
  @op_string
end

Instance Method Details

#concat(term) ⇒ Object



116
117
118
# File 'lib/flounder/expression.rb', line 116

def concat term
  @terms << term
end

#to_sqlObject



120
121
122
123
124
125
126
# File 'lib/flounder/expression.rb', line 120

def to_sql
  "(" +
    @terms.
      map { |t| eval(t) }.
      join(" #{op_string} ") +
    ")"
end