Class: PGB::OperatorCall

Inherits:
Expression show all
Defined in:
lib/pgb/operator_call.rb

Instance Method Summary collapse

Methods included from SQLDisplayable

#inspect, #to_s

Constructor Details

#initialize(operator, expression1, expression2 = nil) ⇒ OperatorCall

TODO Validate and parse operators www.postgresql.org/docs/current/functions.html



7
8
9
10
11
# File 'lib/pgb/operator_call.rb', line 7

def initialize(operator, expression1, expression2 = nil)
  @operator = operator.to_s
  @expression1 = to_expression(expression1)
  @expression2 = to_expression(expression2) if expression2
end

Instance Method Details

#to_sqlObject



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

def to_sql
  if unary?
    "#{operator}#{expression1}"
  else
    "#{expression1} #{operator} #{expression2}"
  end
end